I am using jQuery for a project and probably have a dozen additional jQuery plugins / add-ons (tipsy, unified, jeditable, fancybox, etc. etc.).
As a best practice, should you only load pages when they are needed?
Or is it better for me to just download them all from the very beginning, so that they are in the browser’s cache, and you just need to do it instead of programmatically including the code when necessary?
It depends. You have to make a decision depending on the size and time of downloading files and without them. If all this is a reasonable size with files, you can just include them all. Otherwise, turn them on if necessary. Or you can even turn them on at different times on the user's path through the site, so when they reach a page that requires a lot of them, they don’t have to download everything right away. Unless you're talking about large file sizes (which I doubt), this probably won't make much difference anyway.
In general, you should only load scripts that are required on the page.
Each added file is an additional call to your server (provided that it does not extinguish), adding load and traffic.
, .
, , ?
, , , , .
, , , - 5 , minify request . .
, :
<script type="text/javascript" src="http://www.tylerbel.com/workspace/min/f=workspace/js/jquery-1.4.2.min.js,workspace/js/jquery-ui-1.8.5.custom.min.js,workspace/js/main.js">
, : http://requirejs.org/docs/jquery.html
, PHP, , . , , , js , php. php js script , if. , , , . , $_SESSION ['chatjs'] = '1';... php js if (isset ($ _ SESSION ['chatjs'] )) {include ('whatever.js); ($ _ SESSION [ 'chatjs']); }, 0,035 , , .
Source: https://habr.com/ru/post/1783878/More articles:Getting problems with sn.exe outside of NETFX 4.0 tools - .netWhat is the smallest way to say this: - javascriptspeed up computing? - computer-scienceParallel pipeline in C # - c #In Excel 2010, how can I show the number of occurrences on a specific date in multiple time ranges? - excelConvert signed ints (2 bytes, 16 bits) in double format. With Java - javaHow do you free an XMLHttpRequest object and how do you free an ActiveXObject ("Microsoft.XMLHTTP")? - javascriptssh gave me permission denied! - githubJList with custom renderer - javaLinearLayout image alignment by code - javaAll Articles