Closed tomByrer closed 8 years ago
I think we can assume if sourceMappingURL\s*=
is present in a comment in a file we can consider it minified. The only file I can think of off the top of my head that will break this assumption is bootstrap.css
which has broken sourcemapping iirc
sourceMappingURL\s*=
is a great idea! What should happen if there is:
var sourceMappingURL = somefile.js
? I'm thinking looking for a .map file is better.
Updated original post with test URL & Phase 2.
thats why I said in a comment :)
oops! Fixed top issue
Lookin like a good start. @tomByrer I can give you pointers if you want to learn a bit of python and make a pr
A branch of this issue is validating .map
files: validate .map
points to valid files; ensure x.map
is referenced by some file; Ensure that file is minified... etc
I think https://github.com/jsdelivr/bot/commit/547c10b8e984654140e354630b89e791e8fe21b6 is a reasonable fix based on average line lengths. Essentially I assume if a file has an average line width of 200 characters we classify the file as minified
ref Phase 1 Check sourceMappingURL
/(\/\*+[\s\S]*?sourceMappingURL\s*=[\s\S]*?\*\/)|(\/\/.*?sourceMappingURL\s*=.*?[\r\n])/g
If there is a .map file pointed to, then likely this is a minified file. Other tests should be skipped if true.Phase 2: remove comments (where possible without trashing code) This RegEx test should work:
/(^(\/\*+[\s\S]*?\*\/)|(\/\*+.*\*\/)|^\/\/.*?[\r\n])[\r\n]*/gm
on this test code:Bonus: grabs newlines after comment.
Phase 3