简体   繁体   English

在 Chrome 开发者工具中调试时,任何拆分冗长 JavaScript 的方法

[英]Any way to split lengthy JavaScript when debug in Chrome Developper Tools

Recently I have to debug some JavaScript from a web site, which host around 70 JavaScript files.最近我必须从一个网站上调试一些 JavaScript,该网站托管了大约 70 个 JavaScript 文件。 But some files appear only one line in Google Chrome Developer Tools, but the size of such files are more than 1MB.但是有些文件在谷歌浏览器开发者工具中只出现了一行,但是这些文件的大小都超过了1MB。

You can think if you want to debug this kind of JavaScript with step-in or step-over or even step-out, you just get lost.你可以想,如果你想用 step-in 或 step-over 甚至 step-out 来调试这种 JavaScript,你就会迷失方向。 I downloaded one of such files, and use online code beautify tools to make the JavaScript looks prettier, but I found the file is more than 36,000 lines after the code been beautified.我下载了一个这样的文件,并使用网上的代码美化工具让JavaScript看起来更漂亮,但我发现代码美化后文件超过36000行。

I want to know is there anything like Chrome extension or something built-in in Chrome Developer Tools to make the online JavaScript file looks better.我想知道是否有类似 Chrome 扩展程序或 Chrome 开发人员工具中内置的东西可以使在线 JavaScript 文件看起来更好。 For example, make the above JavaScript file from one line to 36,000 lines, so I can easily debug it.比如把上面的JavaScript文件从1行变成36000行,这样我就可以轻松调试了。

By the way, not all the JavaScript files looks ugly from the same website, some JavaScript file, I can see there are hundreds of lines when doing debug, which is much better to do within only one line.顺便说一句,并不是所有的 JavaScript 文件在同一个网站上看起来都很丑陋,一些 JavaScript 文件,我在调试时可以看到有数百行,最好在一行内完成。

If you want to prettify the source file, just press the {} button at the left bottom, like in the image below (red square):如果您想美化源文件,只需按下左下角的{}按钮,如下图所示(红色方块):

如何美化源文件

By the way, not all the JavaScript files looks ugly from the same website, some JavaScript file, I can see there are hundreds of lines when doing debug, which is much better to do within only one line.顺便说一句,并不是所有的 JavaScript 文件在同一个网站上看起来都很丑陋,一些 JavaScript 文件,我在调试时可以看到有数百行,最好在一行内完成。

Some files may have just one line because they are minified , but what is a minified file?有些文件可能只有一行,因为它们被缩小了,但什么是缩小文件?

A minified file is a version without indentation and with short variables names.缩小文件是没有缩进和短变量名称的版本。 This method is widely used to decrease the file size and improve the user experience, since that file will take less time to load.此方法广泛用于减小文件大小并改善用户体验,因为该文件加载时间较短。 If you are about to deploy a website, I suggest you a further reading about this topic.如果您要部署网站,我建议您进一步阅读有关此主题的内容。

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

相关问题 是否有任何开发人员工具可以调试IE 6中的javascript错误? - Is there any developer tools to debug javascript error in IE 6? 有什么方法可以阻止 div 在 Chrome 开发者工具中滑动? - any way to stop div sliding in Chrome Developer Tools? Chrome 开发者工具不再显示所有 JavaScript 文件 - Chrome developer tools do not show all JavaScript files any more 从 Firefox 开发者工具强制全屏 - Force fullscreen from Firefox Developper tools Chrome Dev 工具中有没有办法不跳过其他 JavaScript 文件? - Is there a way in Chrome Dev tools to not jump through other JavaScript files? 如何使用通过Javascript加载的Chrome Dev工具调试Javascript文件? - How to debug a Javascript file using Chrome Dev tools which is loaded via Javascript? 有用于优化javascript的工具吗? - Any tools for optimizing javascript? 如何使用Chrome开发工具来调试动态添加到页面的head元素的javascript标签? - How to use Chrome dev tools to debug javascript tag added dynamically to a page's head element? 如何在Chrome开发者工具中的JavaScript调试的部分视图中调试脚本? - How to debug a script inside partial view that load by javascript in Chrome Developer Tools? 有没有办法使用javascript检查chrome chrome:// flags / values? - Is there any way to check chrome chrome://flags/ values using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM