简体   繁体   English

CDN托管了javascript库vs下载和缩小

[英]CDN hosted javascript libraries vs downloaded and minified

Looking for some information here mainly. 在这里寻找一些信息主要是。

Recently changed my setup to work with Grunt and LiveReload. 最近改变了我的设置,与Grunt和LiveReload一起工作。 Its great for creating small minified css files from scss files so thats great. 它非常适合从scss文件创建小的缩小css文件,所以非常棒。

However, whats best in terms of JS? 但是,在JS方面最好的是什么? I currently use CDNs for most things such as jQuery, Isotope, TagIt and so on. 我目前使用CDN来处理大多数事情,例如jQuery,Isotope,TagIt等。

I have a few custom JS files which contain my own code for my site, so its okay for me to concatenate them and minify. 我有一些自定义的JS文件包含我自己的网站代码,所以我可以将它们连接起来并缩小。 I understand that having many requests affects performance, hence minifying and concatenating. 我知道有很多请求会影响性能,因此会缩小和连接。

But is it better to download all the libraries and compile them into one JS file to include on my site? 但下载所有库并将它们编译成一个JS文件以包含在我的网站上是否更好? Or keep the external ones linked to a CDN? 或者保持外部链接到CDN?

There are really two considerations here: 这里有两个注意事项:

  • Security 安全
  • Performance 性能

Security 安全

In terms of security, hosting JavaScript yourself puts you in charge, whereas relying on JavaScript from an external domain essentially trusts that domain with the security of your domain (which, depending on your level of trust with that third party, may or may not be acceptable). 在安全性方面,托管JavaScript本身会让您负责,而依赖来自外部域的JavaScript基本上相信该域具有域的安全性(根据您与该第三方的信任程度,可能会或可能不会上可接受的)。 If you use advanced security settings such as Content-Security-Policy , you may need to do some extra work to allow these externally hosted scripts (eg specifically whitelisting the CDN domains in the script-src ). 如果您使用Content-Security-Policy等高级安全设置,则可能需要做一些额外的工作来允许这些外部托管的脚本(例如,在script-src专门将CDN域列入白名单)。

Performance 性能

In terms of performance, using a CDN hosted version -- especially if it is popular -- may give you better caching; 在性能方面,使用CDN托管版本 - 特别是如果它很受欢迎 - 可能会为您提供更好的缓存; however, hosting it yourself and combining it with your other scripts may produce fewer requests. 但是,自己托管并将其与其他脚本相结合可能会产生更少的请求。 In terms of which is actually faster, you will need to do some of your own measurement (I recommend doing an a/b test with real user traffic, which will give you a better idea of whether real users already have the CDN hosted versions of the resource cached or not). 就实际速度而言,您需要进行一些自己的测量(我建议使用实际用户流量进行a / b测试,这样可以让您更好地了解真实用户是否已拥有CDN托管版本资源是否缓存)。

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

相关问题 Google CDN服务器托管本地托管的VS. - Google CDN servers hosted libraries VS locally hosted 加载CDN上托管的JS库的本地版本 - Load local versions of the JS libraries hosted on a CDN 提供CDN中的javascript库与将它们组合为一个并作为单个http连接 - serving javascript libraries from CDN vs combining them as one and serving as a single http connection RequireJS不适用于具有CDN托管库(jQuery)的多页项目 - RequireJS doesn't work on a multipage project with CDN hosted libraries (jQuery) 如何在ng-boilerplate中包含CDN托管的库? - How to include CDN-hosted libraries with ng-boilerplate? 如何选择 CDN 来加载 Javascript 和 CSS 库? - How to choose a CDN to load Javascript & CSS libraries? 不使用公共 CDN 加载 Javascript 库有什么好处吗? - Is there a benefit to NOT using a public CDN to load Javascript libraries? 在性能方面缩小/编译JavaScript与未压缩的JavaScript - Minified/compiled JavaScript vs. uncompressed JavaScript in terms of performance 如何覆盖CDN(其他地方)中托管的javascript库所需的文件? - How to overwrite a file required by a javascript library hosted in a CDN (elsewhere)? 什么知名的JavaScript库位于CDN上,URL是什么? - What well known JavaScript libraries are located on CDN's, and what are the URLs'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM