Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 545
hoge1e3 Avatar asked Jul 18 '16 02:07

hoge1e3


People also ask

What is SourceMap URL?

The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger. Header type.

What is a SourceMap JS?

Definition. A Sourcemap is a file that maps from the transformed source to the original source. It is a mapping between the generated/transpiled/minified JavaScript file and one or more original source files. The main purpose of Sourcemaps is to aid debugging.

What are map files JavaScript?

The . map files are for JavaScript and CSS (and now TypeScript too) files that have been minified. They are called source maps. When you minify a file, like the angular. js file, it takes thousands of lines of pretty code and turns it into only a few lines of ugly code.


1 Answers

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.

like image 113
Mikhail Vitik Avatar answered Oct 23 '22 21:10

Mikhail Vitik