1

Per the Source Map spec §6.2:

There are two suggested ways to link source maps to the output. The first requires a server support to add a HTTP header and the second requires an annotation in the source.

The HTTP header should supply the source map URL reference as:

SourceMap: <url>

[…] The generated code should include a line at the end of the source, with the following form: […]

This recommendation works well for JavaScript, it is expected that other source files will have different conventions. For instance, for CSS /*# sourceMappingURL=<url> */ is proposed.

What is the corresponding convention for HTML? My guesses:

  • <!--# sourceMappingUrl=<url> --> after </html>. (Most likely.)
  • <meta http-equiv="SourceMap" content="<url>" /> in <head>.
  • Mysterious third option.

(Answers to a 2013 question suggest there is no browser support for HTML sourcemaps. I care little for browser support, but I do care for convention.)

4
  • 1
    Actually, using a source map to debug a rendered HTML markup - from the browser or not - is just one usage of source map and arguably not the most valuable. Source maps can also be used to provide resource rebasing - typically to rebase and output images, scripts or any resource that is referenced by an HTML markup, which allows to reference assets relatively in the HTML source. Commented Oct 9, 2023 at 1:00
  • @EricMORAND I have no idea what you're talking about, but it sounds cool. Do you have an example? If so, I could probably deduce the answer to this question from it. Commented Oct 9, 2023 at 8:11
  • I wrote a node module that is able to rebase assets referenced by an HTML document, as long as a source map is available for this HTML document. You can find it there: npmjs.com/package/html-source-map-rebase. If course, the main difficulty is to have a source map - but twing provides this feature and since we use it to render our twig templates, we can fully rebase the assets. There is an example in the README if the library. Commented Oct 9, 2023 at 8:52
  • 2
    And to answer your question, I'm also quite interested into a convention to both reference an external source map and include an inline source map into an HTML document. I'm sure there was a proposal at some point for that - I even wrote a proof of concept about it a while ago. I'll try to find it, but definitely there is nothing official yet. Maybe it is time to jump in and propose something to the spec maintainer: sourcemaps.info/spec.html Commented Oct 9, 2023 at 9:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.