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

不羁岁月 提交于 2020-01-02 02:32:14

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/38427991/which-is-the-base-url-of-sourcemappingurl-relative-from-html-or-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!