What MIME type should I use for JavaScript source-map files?

JavascriptHtmlHttpSource Maps

Javascript Problem Overview


I want to add source maps to my site, but I'd like to exercise some control over how they're served. What is an appropriate MIME type to use for them?

Some data
  • The content itself is JavaScript, but not meant to be executed as such.
  • CDN.js serves http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.map with Content-Type: application/octet-stream.
  • Google serves http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.map with Content-Type: application/json
  • The Source Maps spec states that maps should begin with )]} to prevent them from being evaluated as actual JavaScript (and thus exposing cross-site scripting attacks). That makes the file invalid JSON and valid, but un-runnable JavaScript.

Javascript Solutions


Solution 1 - Javascript

application/json is the best mimetype for sourcemap files.

application/octet-stream might work well with browser devtools, however this mimetype is a signal to browsers to initiate a download. This may cause problems for tools like performance analysis tooling or JS exception tracking that attempt to make sense of the source maps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames A. RosenView Question on Stackoverflow
Solution 1 - JavascriptPaul IrishView Answer on Stackoverflow