Minimize everything to a single file or use CDN

For things like jQuery, etc., it's best to leave it to use the CDN or minimize it to 1 file along with other JS

+4
source share
3 answers

CDN - it may already be cached on users' computers, and you save it for download. Not to mention that it will load faster from the CDN than from your site, in any case, the overhead of one additional connection to capture this diminimus file

+4
source

All your code must be combined and minimized. For libraries, this is a little trickier. CDNs are good in theory, but some studies have shown that they were not really as effective as possible for various reasons.

This means that if you have 50% of missed bids on your CDN, the overhead of additional DNS resolution and additional connection can actually slow you down more than it helps.

In any case, the most important thing is that you should update your miniature / combined JS file so that it has a unique URL for each version of your deployed code. That way, you can set the Expires headers to +10 years and make sure that anyone who downloads it downloads it only once.

Also do not forget to include gzip (mod_deflate in apache), which usually compresses the transfer to 1 / 5-1 / 10th of its original size.

+1
source

The use of CDN is great, as the js file can already be cached from the CDN to the user computer.

But there may be some jQuery plugins and your own site check and other functions that can be shared in different JS files. then minimize + combining is a good approach.

For our ease, we split the code in different files, and when the browser tries to download the content, it has a limit on the number of requests to send to the same server, the CDN leaves your domain, it will be requested without a browser limit so it loads quickly. You need to merge js files to reduce the number of requests from the browser in order to load your page faster.

For me, I use PHP to combine and minimize

In html

<script src="js.php" >

and in php

header ('Content-type: text / javascript');

enable 'js / plugin.js';

enable 'js / validation.js';

You can use output buffering to minimize as well as send this content as gziped to the browser

0
source

Source: https://habr.com/ru/post/1333328/


All Articles