Monday, June 3, 2024
123
rated 0 times [  129] [ 6]  / answers: 1 / hits: 31726  / 10 Years ago, sat, december 27, 2014, 12:00:00

Today I learned that it is possible to include source maps directly into your minified JavaScript file instead of having them in a separate example.min.map file. I wonder: why would anybody want to do something like that?



The benefit of having source maps is clear to me: one can for example debug errors with the original, non-compressed source files while running the minified files. The benefit of minimization is also clear: the size of source files is greatly reduced, making it quicker for browsers to download.



So why on Earth I would want to include the source maps into the minified file, given that the maps have size even greater than the minified code itself?


More From » gulp-sourcemaps

 Answers
32

I searched around and the only reason I could see that people inline source maps is for use in development. Inlined source maps should not be used in production.



The rational for inlining the source maps with your minified files is that the browser is parsing the exact same JavaScript in development and production. Some minifiers like Closure Compiler do more than 'just' minify the code. Using the advanced options it can also do things like: dead code removal, function inlining, or aggressive variable renaming. This makes the minified code (potentially) functionally different than the source file.



This could still be done by referencing external source map files of course, but some people seem to prefer inlining for their build process.


[#68371] Wednesday, December 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
beatrizrheaq

Total Points: 73
Total Questions: 89
Total Answers: 107

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
;