简体   繁体   English

在生产中使用 css/javascript 源映射的性能影响?

[英]Performance impact of using css / javascript source-maps in production?

  • Should source-maps be used in production environment?应该在生产环境中使用 source-maps 吗? Do they provide any benefits other than debugging?除了调试之外,它们是否提供任何好处?
  • Do they impact app load time due to the additional server round-trips?由于额外的服务器往返,它们是否会影响应用加载时间? Are browsers smart enough to load .map assets after app is loaded and rendered?浏览器是否足够智能以在加载和呈现应用程序后加载.map资产?
  • If a browser cannot find the .map asset ( 404 error), would there be performance impact?如果浏览器找不到.map资产( 404错误),是否会影响性能? Should I care about fixing it?我应该关心修复它吗?

Note that fixing the last one may not be as easy as serving the .map assets if there are complicated concat / minify build steps.请注意,如果存在复杂的 concat / minify 构建步骤,修复最后一个可能不像提供.map资产那么容易。

A quick test using Charles Web Proxy shows that source maps are only loaded if developer tools are opened.使用Charles Web Proxy 进行的快速测试表明,在打开开发人员工具时才加载源映射。 If you load a page without dev tools opened, there is no http request for source maps.如果您在打开开发工具的情况下加载页面,则不会对源地图进行 http 请求。

The behaviour was the same in Chrome 43 and Firefox 38. Chrome 43 和 Firefox 38 中的行为是相同的。

So it appears they would be no impact on production environment.所以看起来它们不会对生产环境产生影响。

From HTML5 Rocks:来自 HTML5 摇滚:

Basically it'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.当您为生产构建时,连同缩小和组合您的 JavaScript 文件,您会生成一个源映射,其中包含有关原始文件的信息。 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.当您在生成的 JavaScript 中查询某个行号和列号时,您可以在返回原始位置的源地图中进行查找。 Developer tools (currently WebKit nightly builds, Google Chrome, or Firefox 23+) can parse the source map automatically and make it appear as though you're running unminified and uncombined files.开发人员工具(目前是 WebKit nightly builds、Google Chrome 或 Firefox 23+)可以自动解析源映射并使它看起来好像您正在运行未缩小和未组合的文件。

http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

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

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