DEV Community

Warren
Warren

Posted on

2 1

Ajax'd Javascript in dev tools

Honestly I'm mostly writing this as a note to my self since I have learnt about and then forgotten this particular trick several times over the last few years.

If you're loading javascript through ajax (quite common when working with ASP.NET MVC) then you can give a hint to the browser which enables it to open it in the dev tools with a specific file name. Just add //# sourceURL=filename.js before the closing </script> tag.

e.g.

<script>
    $(function() {
        console.log("wibble")
    })

    //# sourceURL=wibble.js
</script>

From the browser's dev tools you should now be able to open this file by searching for "wibble.js" (Ctrl+P brings up the search)

Top comments (1)

Collapse
 
dowenb profile image
Ben Dowen

Nice trick thanks for sharing.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay