Which is the base url of sourcemappingurl: relative from html or js?
Asked Answered
T

1

13

Suppose that there is a js file with source-map in subdirectory of a html file.

  • index.html (uses js/myjs.js)
  • js/myjs.js
  • js/myjs.js.map

then which is the sourceMappingURL comment of myjs.js ?

//# sourceMappingURL=myjs.js.map

or

//# sourceMappingURL=js/myjs.js.map
Tham answered 18/7, 2016 at 2:57 Comment(0)
F
11

I lookup to the specification.

When the source mapping URL is not absolute, then it is relative to the generated code’s “source origin”. The source origin is determined by one of the following cases:

  • If the generated source is not associated with a script element that has a “src” attribute and there exists a //# sourceURL comment in the generated code, that comment should be used to determine the source origin. Note: Previously, this was “//@ sourceURL”, as with “//@ sourceMappingURL”, it is reasonable to accept both but //# is preferred.
  • If the generated code is associated with a script element and the script element has a “src” attribute, the “src” attribute of the script element will be the source origin.
  • If the generated code is associated with a script element and the script element does not have a “src” attribute, then the source origin will be the page’s origin.
  • If the generated code is being evaluated as a string with the eval() function or via new Function(), then the source origin will be the page’s origin.

So if you use <script src="js/myjs.js"> in index.html the js/myjs.js.map is used.

Foyer answered 1/12, 2016 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.