Bundling .js files vs CDN

前端 未结 4 1298
有刺的猬
有刺的猬 2020-12-23 17:06

In order to improve performance of our web pages, we are recommended to use CDNs to serve .js files on our web pages. That makes sense.

Also, we are rec

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 18:06

    There's a few things you need to think about...

    How much of the JS do you need to load early in the page load, and how much can you delay until later?

    If you can delay loading JS (e.g. put it at the bottom of the page) or load it asynchronously as Google Analytics does, then you will minimise the amount of time downloading the JS spends blocking the UI thread.

    After working out how the load of the JS can be split, I'd deal with the merge / minify of the various JS files - cutting down HTTP requests is key to improving performance.

    Then look at moving to the CDN and ensure the CDN can serve the JS content compressed and allow you to set headers so it's "cached forever" (you'll need to version the files if you cache forever). A CDN helps reduce the latency but will also reduce size by being cookieless

    Other thing you might want to consider is setting up a separate domain for static content, point it to your server(s) while you sort things out and then switch to a CDN if it looks worthwhile.

    Andy

提交回复
热议问题