Search code examples
javascriptsource-maps

Source map syntax - hash or at-sign


I know I've seen source maps done a couple ways and am not finding much info on which one is preferred, better supported, or more recent/future-proof

//@ sourceURL=foo.js

//# sourceURL=foo.js

Which one, which one? What difference does it make?


Solution

  • Use:

    //# sourceURL=foo.js
    

    The original source map spec used '@', but this conflicted with 'conditional compilation' (which is activated with @cc_on) in IE<11, which runs code in comments, and would result in errors of the type:

    'foo' is undefined

    When trying to assign the 'js' property, from the 'foo' object to the sourceURL variable. (See https://msdn.microsoft.com/library/8ka90k2e(v=vs.94).aspx for details of how @cc_on works).

    So the spec was changed to use '#' instead.

    Source: https://developers.google.com/web/updates/2013/06/sourceMappingURL-and-sourceURL-syntax-changed?hl=en