Problem/Motivation
Core has added minified JS libaries. These files reference sourceMappingURL for modern browsers. Chrome will cause a lot of 404 file not found errors in server logs for this reason. I have already developed a solution for D7 and D8 to solve these issue in aggregated JS files. See #2400287: Remove all occurences of sourceMappingURL and sourceURL when JS files are aggregated. However we should add the missing .MAP files to allow easier debugging and remove these many 404 errors.
Proposed resolution
We have some options:
- Leave it as is with tons of 404 errors and safe 180kb .map files on page load. Very bad idea.
- Add the missing .map files to the asset folders. This will add around 180kb of size to the web pages. But in aggregated JS files we save these as we commit #2400287: Remove all occurences of sourceMappingURL and sourceURL when JS files are aggregated. May not really the best solution.
- Remove the
//# sourceMappingURL=lines from all minified JS files. That means we are not shipping with original file versions. It's a reasonable good compromise I think.
Remaining tasks
May write documentation that MAP files should always exists or //# sourceMappingURL= removed from minified files to solve the 404 errors if these MAP files do not exists. For aggregated files we need to commit #2400287: Remove all occurences of sourceMappingURL and sourceURL when JS files are aggregated to remove //# sourceMappingURL= automatically.
User interface changes
None
API changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | interdiff.txt | 51.99 KB | pguillard |
| #41 | Issue-2400675-by-hass-Missing-map-files-causing-404-41.patch | 179.71 KB | pguillard |
| #38 | debug-map-jquery-step2-2.png | 181.17 KB | nod_ |
| #38 | debug-map-jquery-step2.png | 137.06 KB | nod_ |
| #38 | debug-map-jquery-step1.png | 199.09 KB | nod_ |
Comments
Comment #1
hass commentedVariant number 2 that adds the missing .MAP files.
Comment #2
hass commentedComment #3
hass commentedAnd here the variant number 3 with all
sourceMappingURLremoved from minified JS files.Comment #4
hass commentedComment #5
hass commentedComment #6
hass commentedComment #7
hass commentedComment #8
hass commentedComment #9
droplet commentedPlan B:
Educating developers to switch off SourceMap supports in Console. If you're not going to use Source Map, no reason to Enable it anymore :). It's same to CSS Source Map.
Comment #10
nod_As far as I know sourcemaps are not enabled by default in all browsers no?
I wouldn't be against adding the sourcemap files but does that means we need to ship the unminified file as well?
Comment #11
hass commentedIt's enabled by default in Google Chrome and with Firefox developer tools installed. Educating sound not like an option here.
Only if sourceURL is used as I know and until now I have not found any lib that integrated this.
Comment #12
wim leersWhat is this blocked on? I don't see any reason not do this?
Comment #13
hass commentedWhy do you think it is blocked? I see no reason.
Comment #14
berdirWim didn't say it is blocked, he asked why, the reason for that being that nod_ did RTBC the patch yet.
I'm wondering how we test that this will not come back as a regression? There are also a bunch of other issues to update JS libraries and/or replace them with minified versions.
Should we have a test that scans for min.js files and this string?
Comment #15
hass commented@Bedir: there is also this follow up #2400287: Remove all occurences of sourceMappingURL and sourceURL when JS files are aggregated. Maybe we can load all assets, scan them and force a test fail if it exists? No idea how we can load all assets except test ones.
Comment #16
webchickGiven this causes a nasty 404 error on every page load of a default install, escalating to major.
Comment #17
droplet commentedComment #18
alexpottre #14 I agree, this is will be such an easy regression to have. Are the very least I think we should implement a test that scans minified js for
//# sourceMappingURL=and throws an error if the file does not exist.Comment #19
droplet commentedWe review every patches, write a test for it doesn't a crazy idea ? ( I think Drupal is 100% won't add .map files in CORE)
http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests
EDIT:
I told it because I don't count it as "regression". These patches are provided by me and I patch it with source map statement but without .map files intentionally (and few reviewer mentioned the 404 errors when they do reviews). However now, the community has different thought on it. I think any extra tests will slow down test performance a bit. While we can make sure we won't make same mistakes by manual reviews, testcase isn't a required IMO.
Comment #20
hass commentedComment #21
sqndr commented/
Comment #22
sqndr commentedComment #23
sqndr commentedComment #24
geerlingguy commentedAgreed with #15 and #18; this annoys me to no end when I'm debugging a module with a fresh D8 install, and I always notice console errors. Just a tiny distraction, since after I click and see the '.min.map' warning I know it's not one of my modules. But it's more than a minor nuisance.
I just wish Chrome wouldn't complain so loudly about it :P
Comment #25
kevinquillen commentedNo. Users should not have to configure their browser to make an error Drupal go away; the root issue should be addressed.
Comment #26
kevinquillen commentedAs a side note, this error is also triggered if you have an empty .install file in a module.
Comment #27
nlisgo commentedComment #28
cilefen commentedThe 404's are not a production error because they only occur in the context of browser devtools, as I have demonstrated in #1341792-77: [meta] Ship minified versions of external JavaScript libraries.
Comment #29
cilefen commentedComment #30
hass commentedThan I think we can simply add the map files to core. That is patch #1.
Comment #31
hass commentedhiding #3 as #1 is the best solution.
Comment #32
droplet commentedWhile we agreed to provide such features, we could consider further way to provide sourcemap for all CORE / Contributed modules.
https://github.com/koala-framework/sourcemaps
Comment #33
nod_All right I didn't know the dev tool thing. Let's pull the trigger on that one and figure out what we want to do exactly with them.
As I understand it the sourcemaps added here are useless because we don't have the actual unminified source along with it, let's discuss in a follow-up what we want to do exactly and to what extend we support it in core (including the need for tests).
404 went away with the patch so yay.
Comment #35
hass commentedThe source maps here are not useless. They are for the minified files that already exists in core.
Comment #37
hass commentedComment #38
nod_See the screenshots, when map files are present if I debug something (step1.png) and step into a jQuery function (step2.png) I get nothing because the unminified source is not present.
If I add the jquery-2.1.3.js file it's as expected: see step2-2.png screenshot.
Comment #39
alexpott@nod_ do you think the solution in #1 is the correct solution?
@hass can you confirm that the sourcemaps correspond to the correct versions - we might have updated libraries in the meantime. Also rtbc-ing your own patches makes it more difficult to commit patches because I have no idea if the patch is reviewed and tested by the community.
Comment #40
nod_Yes, that's the way to go. We make debugging easier while using only minified files. We're talking about getting rid of 404 and this patch does it, I would say we get the unminified versions in once all the details have been figured out in a follow-up.
From my experience the libs we're using are very stable now and we rarely run in bugs where we need to look into what the libraries are doing. I can only think of toolbar/quickedit during backbone update, and at this point we're not making anything new anymore. My point is that it would be fine to commit this patch as is now, and figure out the rest later.
The rest being details beyond jquery, backbone and underscore. Do we want that for all our vendor libs, should we have that for core files as well, etc.?
Comment #41
pguillard commentedI suggest this new patch with the lastest underscore v1.8.3 sourcemap
Comment #42
rteijeiro commentedIt's RTBC unless @nod_ says anything else :)
Comment #43
nod_Ok with me :)
Comment #44
alexpottCommitted 1daa951 and pushed to 8.0.x. Thanks!
Comment #46
wim leersHurray!
Comment #48
esquist commentedSo, do we need to patch a 8.8.2 install or is it in the core allready?