简体   繁体   English

大型项目的Javascript / jQuery优化(社交媒体)

[英]Javascript/jQuery optimization for large projects (social media)

I am developing a social media website of the scale of LinkedIn, and I am struggling with few things related to JS. 我正在开发一个具有LinkedIn规模的社交媒体网站,并且我在与JS相关的事情上苦苦挣扎。 As project is going on, the requirement of JavaScript/jQuery is increasing. 随着项目的进行,对JavaScript / jQuery的需求正在增加。 I am guessing by the end of the project, jQuery required on each page will be of average file size 1.5MB which is a bad idea. 我猜到项目结束时,每个页面上所需的jQuery的平均文件大小为1.5MB,这是一个坏主意。 Functions like image upload, comments, like, updates is almost on every page. 图像上载,评论之类的功能,更新等几乎在每个页面上。

My Question here is How to optimize jQuery? 我的问题是如何优化jQuery? Any tricks or concept that I can use on this project which will lower file size as well as do these functions (there are much more than just above ones)? 我可以在此项目上使用的任何技巧或概念都会降低文件大小以及这些功能(不仅仅是上面的功能)吗?

Here I have already implemented: 1. Compress/Minify jQuery by PHP plugin 在这里,我已经实现了:1.通过PHP插件压缩/缩小jQuery
2. Use jQuery.getScript() to load file only when it required 2.仅在需要时使用jQuery.getScript()加载文件
3. Divide one large JS file into few separate files to finish loading faster 3.将一个大型JS文件分成几个单独的文件,以更快地完成加载
4. HTML optimization (Google Pagespeed) 4. HTML优化(Google Pagespeed)

I've heard of people using YUI Compressor, which 'has a better compression ratio' than most other tools. 我听说有人使用YUI Compressor,它比大多数其他工具“具有更好的压缩率”。 Not sure what you're using for compression at the moment, but this could provide a slight improvement. 不确定当前用于压缩的内容,但这可能会有所改善。 http://yui.github.io/yuicompressor/ http://yui.github.io/yuicompressor/

Use a CDN (Content Delivery Network) to deliver jQuery. 使用CDN(内容交付网络)交付jQuery。 The browser will most probably cache the library and each page that loads, won't actually be needing to download the library again. 浏览器很可能会缓存该库,并且加载的每个页面实际上都不需要再次下载该库。 This, if i'm not wrong, is one of the main reasons CDN's are used. 如果我没看错,这是使用CDN的主要原因之一。

Otherwise, you should rethink your dependency/development strategy since you might not need jquery after all on each page. 否则,您应该重新考虑您的依赖关系/开发策略,因为您可能根本不需要在每个页面上都使用jquery At least not whole of it. 至少不是全部。

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

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