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:

  1. Leave it as is with tons of 404 errors and safe 180kb .map files on page load. Very bad idea.
  2. 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.
  3. 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

Comments

hass’s picture

Status: Active » Needs review
StatusFileSize
new177.83 KB

Variant number 2 that adds the missing .MAP files.

hass’s picture

Issue summary: View changes
hass’s picture

And here the variant number 3 with all sourceMappingURL removed from minified JS files.

hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
droplet’s picture

Plan 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.

nod_’s picture

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?

hass’s picture

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.

It's enabled by default in Google Chrome and with Firefox developer tools installed. Educating sound not like an option here.

I wouldn't be against adding the sourcemap files but does that means we need to ship the unminified file as well?

Only if sourceURL is used as I know and until now I have not found any lib that integrated this.

wim leers’s picture

What is this blocked on? I don't see any reason not do this?

hass’s picture

Why do you think it is blocked? I see no reason.

berdir’s picture

Wim 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?

hass’s picture

@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.

webchick’s picture

Priority: Normal » Major

Given this causes a nasty 404 error on every page load of a default install, escalating to major.

droplet’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

re #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.

droplet’s picture

We 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.

hass’s picture

Assigned: » Unassigned
sqndr’s picture

StatusFileSize
new468.66 KB

/

sqndr’s picture

Issue summary: View changes
sqndr’s picture

Issue summary: View changes
geerlingguy’s picture

Agreed 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

kevinquillen’s picture

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.

No. Users should not have to configure their browser to make an error Drupal go away; the root issue should be addressed.

kevinquillen’s picture

As a side note, this error is also triggered if you have an empty .install file in a module.

nlisgo’s picture

Issue tags: +Needs tests
cilefen’s picture

The 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.

cilefen’s picture

hass’s picture

Than I think we can simply add the map files to core. That is patch #1.

hass’s picture

hiding #3 as #1 is the best solution.

droplet’s picture

While 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

nod_’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests

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.

Status: Reviewed & tested by the community » Needs work
hass’s picture

The source maps here are not useless. They are for the minified files that already exists in core.

hass’s picture

Status: Needs work » Reviewed & tested by the community
nod_’s picture

StatusFileSize
new199.09 KB
new137.06 KB
new181.17 KB

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.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

@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.

nod_’s picture

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.?

pguillard’s picture

  • I agree with @nod_ to commit patch #1 choice
  • I can confirm that the sourcemaps (and minified files) correspond to the correct last production versions for backbone v1.1.2, and jQuery v2.1.3.
  • But it seems that the underscore sourcemaps is the wrong file

I suggest this new patch with the lastest underscore v1.8.3 sourcemap

rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

It's RTBC unless @nod_ says anything else :)

nod_’s picture

Ok with me :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1daa951 and pushed to 8.0.x. Thanks!

  • alexpott committed 1daa951 on
    Issue #2400675 by hass, pguillard: Missing .map files causing 404 file...
wim leers’s picture

Hurray!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

esquist’s picture

So, do we need to patch a 8.8.2 install or is it in the core allready?