如果Chrome DevTools报告的是.map文件的404(可能是 jquery-1.10.2.min.map , jquery.min.map 或 jquery-2.0.3.min.map ,但可能会发生任何事情),首先要知道的是,这只是在使用DevTools时才会被请求 . Your users will not be hitting this 404.
基本上它's a way to map a combined/minified file back to an unbuilt state. When you build for production, along with minifying and combining your JavaScript files, you generate a source map which holds information about your original files. When you query a certain line and column number in your generated JavaScript you can do a lookup in the source map which returns the original location. Developer tools (currently WebKit nightly builds, Google Chrome, or Firefox 23+) can parse the source map automatically and make it appear as though you'重新运行未组合和未组合的文件 . (阅读更多关于此here)
11 回答
如果Chrome DevTools报告的是.map文件的404(可能是
jquery-1.10.2.min.map
,jquery.min.map
或jquery-2.0.3.min.map
,但可能会发生任何事情),首先要知道的是,这只是在使用DevTools时才会被请求 . Your users will not be hitting this 404.现在您可以解决此问题或禁用源映射功能 .
修复:获取文件
接下来,这是一个简单的解决方案 . 前往http://jquery.com/download/并单击您的版本的 Download the map file 链接,您也需要下载未压缩的文件 .
拥有映射文件允许您通过原始源调试缩小的jQuery,如果您不喜欢处理变量名称(如
a
和c
),这将节省大量时间和挫败感 .有关源图的更多信息:An Introduction to JavaScript Source Maps
道奇:禁用源图
您可以在设置中完全禁用JavaScript源 Map ,而不是获取文件 . 如果您从未计划在此页面上调试JavaScript,那么这是一个很好的选择 . 使用DevTools右下角的cog图标打开设置,然后:
按照其他答案中的说明操作后,我需要从 Map 文件中删除该版本,以便我能够使用 .
示例:重命名
至
如果要获取源映射文件的不同版本,可以使用此链接http://code.jquery.com/jquery-x.xx.x.min.map
相反,x.xx.x会输入您的版本号 .
注意:您使用此方法获得的某些链接可能会被破坏:)
Download Map 文件和jQuery的未压缩版本 . 把它们与缩小版本放在一起:
在您的HTML中包含缩小版本:
登入Google Chrome:
阅读Introduction to JavaScript Source Maps
熟悉Debugging JavaScript
新版本的jQuery需要这个文件http://code.jquery.com/jquery-1.10.2.min.map
此文件描述了此文件的可用性http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
Update:
jQuery 1.11.0 / 2.1.0
// sourceMappingURL comment is not included in the compressed file .
jQuery 1.11.0 / 2.1.0 // sourceMappingURL注释不包含在压缩文件中 .
正如在
jQuery 1.11.0/2.1.0 Beta 2 Released
中宣布的那样,源 Map 注释将被删除,因此该问题不会出现在jQuery
的较新版本中 .这是官方公告:
无论如何,如果您需要使用源 Map ,它仍然可用:
Here您可以找到有关更改的更多详细信息 .
Here您可以通过
jQuery 1.11.0/2.1.0 Released
找到已删除缩小文件中的源 Map 注释的确认 .假设您已检查过该文件实际存在于服务器上,这也可能是由于您的Web服务器限制了所提供的文件类型:
在Apache中,如果您使用的是mod_rewrite,可以使用<FilesMatch> directive或_495433来完成 .
在IIS中,您需要查看Web.config file .
您可以通过删除该行来删除404
从jQuery文件的顶部开始 .
jQuery文件的顶部将如下所示 .
只需改变它
源 Map 的用途
基本上它's a way to map a combined/minified file back to an unbuilt state. When you build for production, along with minifying and combining your JavaScript files, you generate a source map which holds information about your original files. When you query a certain line and column number in your generated JavaScript you can do a lookup in the source map which returns the original location. Developer tools (currently WebKit nightly builds, Google Chrome, or Firefox 23+) can parse the source map automatically and make it appear as though you'重新运行未组合和未组合的文件 . (阅读更多关于此here)
至少我了解浏览器Chrome,它默认情况下不会禁用源映射 . 这意味着您的应用程序的用户将默认触发此源映射请求 .
您可以通过从JavaScript文件中删除
//@ sourceMappingURL=jquery.min.map
来删除源映射 .我遇到了同样的问题 . 我的原因是Grunt连接我的JavaScript文件 .
我使用
;\n
作为分隔符,导致源映射的路径为404 .所以开发工具正在寻找
jquery.min.map;
而不是jquery.min.map
.我知道这不是原始问题的答案,但我确信其他人也有类似的Grunt配置 .