Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 535
James A. Rosen Avatar asked Nov 11 '13 17:11

James A. Rosen


People also ask

How do you use source maps in JavaScript?

To enable source maps in Google Chrome, go to Developer Tools, click the little cog icon, and then make sure that “Enable Javascript source maps” is checked. That's it.

What is MIME type to download any type of file?

Summary. MIME types enable browsers to recognize the filetype of a file which has been sent via HTTP by the webserver. As a result the browser is able to choose a suitable displaying method. Common MIME types are for example text/html for html-files or image/jpeg for jpeg-files.


1 Answers

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.

like image 69
Paul Irish Avatar answered Sep 24 '22 02:09

Paul Irish