Was browsing through apache logs and found interesting thing:
When a users access any page where I have included jquery, apache tries to get jquery-xxx.min.map file and failed with 404 error. Here is an example:
xxx.xxx.xxx - - [Date:TIME +0000] "GET /js/lib/jquery-1.10.2.min.map HTTP/1.1" 404 3134 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
This is not a surprise, because I clearly do not have this min.map file.
I do not like this behavior.
Looking in jquery source code, I have found
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-1.10.2.min.map
First thing is that this sourceMappingURL is in the comment, and there is no other hits. When I just removed it, 404 error disappeared.
I have no questions that people from jquery knew what are they doing, but can anyone explain me:
The only relevant thing I was able to found is this link and as far as I understood (please right me if I am wrong) that:
- it generates some errors in IE (I was viewing through Chrome)
- it is deprecated (I am using the latest version of jQuery at the time of being)
- it is used for debugging purposes (have not understood for what debugging purposes)
There are several ways to remove the error.
By default Chrome will enable source maps. You can disable this by opening the Developer Tools and changing the general settings. Uncheck the Enable source maps option. This of course won't fix the error on Apache.
Change your pages to use a CDN served by jQuery or Google rather than using a local version. This will stop your local Apache from showing the issue in your logs.
Alternatively, you will have to rewrite the comment at the top of your local version of jquery-1.10-2.min.js to stop this error. Otherwise you'll need to wait for a patch by jQuery.
From:
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-1.10.2.min.map
*/
To:
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license */
sourceMappingURL is an HTML5 feature which has under gone some changes in the last months.
More info on sourceMappingURL: Introduction to JavaScript Source Maps, March 2012
See the following link related to recent changes to sourceMappingURL:
sourceMappingURL and sourceURL syntax changed, June 2013
JQuery 2.1.4 min file causes 404 with IE > 8 when it attempts to download map file. jquery-2.1.4.min.js has following as last line:
//# sourceMappingURL=jquery.min.map
There are two (good) options to fix this.
Option ONE (preferred, keeps the map file request for production)
Step 1. Move last line in min file to second line as below
/*! jQuery v2.1.4 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */
//# sourceMappingURL=jqueryminmap
Notice that dots are removed in jquery.min.map.
Step 2. Add a bundle for map file with no transforms.
var jquerymap = new ScriptBundle("~/bundles/jqueryminmap").Include(
"~/Scripts/jquery-2.1.4.min.map");
jquerymap.Transforms.Clear();
bundles.Add(jquerymap);
Even though this is the preferred method it requires you to change the source file (jquery-2.1.4.min.js). Hopefully, JQuery developer or IE will fix the issue in the next release.
Option TWO
Add jquery bundle without removing transforms (which causes MVC engine to remove last line in 2.1.4 min file which in turn will tell browser not to request map file).
var jquery = new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js");
bundles.Add(jquery);
Both of these options will fix the 404 on map file for IE > 8 and JQuery 2.1.4 but I prefer option ONE.