简体   繁体   English

我应该将javascript框架与我的应用程序捆绑在一起还是使用公共CDN?

[英]Should I bundle a javascript framework with my application or use a public CDN?

About two or three years ago, I would have summarised the answer to this as. 大约两三年前,我会总结出这个问题的答案。

  • compile all js to one file and minify. 将所有js编译为一个文件并缩小。
  • complie all css to one file and minify. 将所有css编译成一个文件并缩小。
  • load external scripts async. 加载外部脚本异步。
  • set cache control headers to the far future. 将缓存控制头设置为遥远的未来。
  • fingerprint asset urls for invalidation. 指纹资产网址失效。
  • use your own CDN. 使用自己的CDN。

Now applications seem to be much heavier on javascript. 现在应用程序似乎在javascript上更重。 And I have seen evidence that browsers are able to open more parallel connections. 我已经看到证据表明浏览器能够打开更多并行连接。

What currently is the best practice for web performance when including static assets. 当包含静态资产时,目前最佳的Web性能实践。

When I use a framework like angular, backbone or ember, should I bundle the framework with my application or use a public cdn (like googles https://developers.google.com/speed/libraries/ ) and just bundle my application code? 当我使用像angular,backbone或ember这样的框架时,我应该将框架与我的应用程序捆绑在一起,还是使用公共cdn(如googles https://developers.google.com/speed/libraries/ )并捆绑我的应用程序代码?

I would say the answer is...it depends. 我会说答案是......这取决于。 I appreciate that isn't very useful so I'll expand. 我很欣赏这不是很有用所以我会扩展。

  • If you're writing an internal (intranet) application it would be better, and more efficient, to bundle the framework into your app. 如果您正在编写内部(Intranet)应用程序,那么将框架捆绑到您的应用程序中会更好,更有效。 Your users will then only need to pull files from the local network. 然后,您的用户只需从本地网络中提取文件。 If you have multiple internal apps using the same framework then an internal CDN would be a good option. 如果您有多个使用相同框架的内部应用程序,那么内部CDN将是一个不错的选择。
  • If your users are unlikely to access other apps that use the same framework then you won't get any benefit from a CDN (unless they're in a different part of the world to your server) but there are no real downsides either. 如果您的用户不太可能访问使用相同框架的其他应用程序,那么您将无法从CDN获得任何好处(除非他们与您的服务器位于世界的不同部分),但也没有真正的缺点。
  • If you want to auto update to the latest version of a library (99 times out of 100 this is a bad idea) you can use a CDN to provide the current version automatically. 如果要自动更新到库的最新版本(100次中有99次这是一个坏主意),您可以使用CDN自动提供当前版本。
  • If you have bandwidth concerns using a CDN can alleviate this as your users will be downloading the files from someone else. 如果您有使用CDN的带宽问题可以减轻这种情况,因为您的用户将从其他人下载文件。
  • If your application js will change frequently then, if you bundle all js together, you'll force a redownload of all the framework libraries. 如果您的应用程序js经常更改,那么,如果将所有js捆绑在一起,您将强制重新下载所有框架库。 Obviously, there are simple ways to get around this such as bundling libraries separately. 显然,有一些简单的方法可以解决这个问题,例如单独捆绑库。

For external apps I'd say using a CDN is the right choice. 对于外部应用程序,我认为使用CDN是正确的选择。

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

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