简体   繁体   English

为什么我看到的所有代码都只限于几行?

[英]Why is all code I see confined to only a few lines?

I'm fairly new to programming and have been taking courses on Lynda to learn the fundamentals. 我对编程还不陌生,一直在上Lynda课程以学习基础知识。 I have some knowledge of Java and HTML, but I wanted to refresh my memory so I can start learning Objective-C. 我对Java和HTML有所了解,但是我想刷新自己的记忆,以便可以开始学习Objective-C。 The Lynda course has us working in JavaScript because of its pretty core syntax. Lynda课程因其漂亮的核心语法而使我们使用JavaScript进行工作。 So, in order to get a point of reference, I tried downloading some .js files integrated into HTML pages from various sources. 因此,为了获得参考,我尝试从各种来源下载一些集成到HTML页面中的.js文件。 However, this proved to be unhelpful and I am at a loss for understanding because of the way the files are formatted. 但是,这被证明是无济于事的,并且由于文件的格式化方式,我不知所措。 It seems as if most files put one line of code after the other. 似乎大多数文件都将一行代码放在另一行之后。 I realize that because of flexible whitespace restrictions with JavaScript that this does not hinder the way the code runs, but why did the developers choose to put it all on one line like that? 我意识到由于JavaScript的灵活空白限制,这并不妨碍代码运行,但是为什么开发人员选择将所有内容都放在这样的一行上? They obviously didn't write the code that way, as that would be extremely tedious and hard to work with, so why did it come out that way when I try to view it? 他们显然没有那样写代码,因为那将是非常繁琐且难以操作的,所以当我尝试查看它时为什么会以这种方式出现? Is it just something that happens when you try to download the resources of a page? 当您尝试下载页面资源时,是否只是发生了什么? Any clarification would be appreciated. 任何澄清将不胜感激。

Below is a photo of a JavaScript file I tried viewing. 下面是我尝试查看的JavaScript文件的照片。 As you can see, all the code is restricted to one single line. 如您所见,所有代码都限于一行。

在此处输入图片说明

Also, if anyone could offer some insight about where to go after I've finished my course if I'm looking to develop for iOS, that would be greatly appreciated. 另外,如果我要为iOS开发,如果有人可以在完成课程后提供一些建议,那将不胜感激。 Lynda also offers an Objective-C Essentials course, as well as an iOS Development course, but I feel like it's a pretty linear path that could be expanded on greatly with some literature or other online documentation. Lynda还提供了Objective-C Essentials课程以及iOS开发课程,但是我觉得这是一条非常线性的路径,可以通过一些文献或其他在线文档来扩展。

what you are seeing is a minified version of the javascript file. 您所看到的是javascript文件的缩小版本 The main advantage of minification is that it reduces the amount of data that needs to be transferred (bandwidth usage). 最小化的主要优点是它减少了需要传输的数据量(带宽使用量)。

If you wish to view the code in human readable format, you can use online tools like this 如果你想在人类可读的格式来查看代码,你可以像使用在线工具

Yes as karthikr said it's minified. 是的,正如karthikr所说的那样缩小。 Which means its all there but without the line breaks. 这意味着所有内容都在其中,但没有断线。 So to see it all you have to scroll right. 因此,要查看所有内容,您必须向右滚动。

Or you can use http://jsbeautifier.org/ to bring back the break lines. 或者,您可以使用http://jsbeautifier.org/带回中断线。

There are several reasons for minifying javascript. 缩小javascript的原因有很多。 One is that it makes the code less readable (yeah, some devs don't want you to "steal" functions and see what it does easily). 其一是它使代码的可读性降低(是的,有些开发人员不希望您“窃取”功能并轻松地查看其功能)。 Another, and a big part of why, is that it reduces bandwidth. 另一个(也是其中一个很大的原因)是它减少了带宽。 A file with long variable names and whitespaces everywhere can be multiple times bigger than a minified version - so it improves performance! 带有长变量名和空格的文件比缩小版本的文件大很多倍-因此可以提高性能!

Bandwidth costs money, especially for users and especially if they're on mobile devices with a bandwidth limit. 带宽要花钱,特别是对于用户而言,尤其是如果用户使用的是带宽受限的移动设备。

So to solve this problem developers will minimize the file size of what ever they can. 因此,要解决此问题,开发人员将最大程度地减小文件大小。

The JavaScripts you are seeing have been minified by libraries such as Uglify or YUI compressor (list not exhaustive). 您所看到的JavaScript已被诸如Uglify或YUI压缩程序之类的库压缩(列表不详尽)。

Doing this will take out unnecessary whitespace and reduce the lengths of variable and function names that are not globally exported. 这样做将删除不必要的空格,并减少未全局导出的变量和函数名称的长度。

Developers may also gzip the files too which will reduce the filesize even further. 开发人员也可以gzip文件,这将进一步减小文件大小。

Edit: grammar 编辑:语法

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

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