简体   繁体   English

Web浏览器如何找到JavaScript文件的源映射?

[英]How do web browsers find a source map for a JavaScript file?

The following article explains that in order to find the source map of a JavaScript file such as jQuery , the web browser looks inside the JavaScript code and looks for the line containing the sourceMappingURL directive embedded in a JavaScript comment. 下一篇文章解释说,为了找到JavaScript文件(例如jQuery)的源映射,Web浏览器在JavaScript代码内部查找并寻找包含嵌入在JavaScript注释中的sourceMappingURL指令的行。 For instance, the jQuery 1.9.0 minified file contains such a directive at the end of a file. 例如, jQuery 1.9.0压缩文件在文件末尾包含这样的指令。 However, the more recent jQuery 1.11.1 minified distribution does not contain such a directive, but a jQuery 1.11.1 map file is also distributed with this (final stable jQuery 1) version. 但是,最新的jQuery 1.11.1精简发行版不包含这样的指令,但是jQuery 1.11.1映射文件也随此版本(最终稳定的jQuery 1)一起发行。 So how does the web browser find the map file for the minified file. 那么,Web浏览器如何找到缩小文件的地图文件。

I guess the convention of web browsers looking for the sourceMappingURL directive was dropped in favor of following the naming convention of looking for a file of the same name, with .js replaced by .min . 我猜想Web浏览器寻找sourceMappingURL指令的sourceMappingURL被放弃了,而是遵循了寻找同名文件的命名约定,用.min替换了.js Is this what happened? 这是发生了什么吗?

According to the documentation for the recently released Firefox Developer Edition, such browser still seems to be looking for the sourceMappingURL directive. 根据最近发布的Firefox Developer Edition的文档,此类浏览器似乎仍在寻找sourceMappingURL指令。

Thanks. 谢谢。

The reasoning behind dropping source mapping from recent versions is described on the JQuery blog JQuery博客中描述了从最新版本删除源映射的背后原因。

This release does not contain the sourcemap comment in the minified file. 此版本在缩小的文件中不包含源地图注释。 Sourcemaps have proven to be a very problematic and puzzling thing to developers, spawning hundreds of confused developers on forums like StackOverflow and causing some to think jQuery itself was broken. 对于开发人员来说,源地图已被证明是一个非常棘手的问题,它在诸如StackOverflow之类的论坛上催生了成百上千的开发人员,并使某些人认为jQuery本身已损坏。

We'll still be generating and distributing sourcemaps, but you will need to add the appropriate sourcemap comment at the end of the minified file if the browser does not support manually associating map files (currently, none do) . 我们仍将生成和分发源地图,但是如果浏览器不支持手动关联地图文件(当前,不支持),则需要在缩小文件的末尾添加适当的源地图注释 If you generate your own jQuery file using the custom build process, the sourcemap comment will be present in the minified file and the map is generated; 如果您使用自定义构建过程生成自己的jQuery文件,则源地图注释将出现在缩小的文件中并生成地图。 you can either leave it in and use sourcemaps or edit it out and ignore the map file entirely. 您可以将其保留并使用源地图,也可以将其编辑并完全忽略地图文件。

We hope to bring back and improve sourcemap support in the future, but at the moment neither the design nor the implementation seem suited for situations like jQuery's, where there are widely distributed files on CDNs. 我们希望将来能带回并改善对Sourcemap的支持,但是目前,设计或实现似乎都不适合jQuery之类的情况,在jQuery中CDN上的文件分布广泛。 We'd like sourcemaps (and browsers supporting them) to gracefully handle situations like file renaming or missing files. 我们希望源映射(以及支持它们的浏览器)能够正常处理文件重命名或文件丢失等情况。 See our bug ticket for more information. 有关更多信息,请参见我们的故障单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM