Is there a way to load javascript without executing it? I want to reduce page load time, so I try to "lazy load" the same amount of javascript on the page while the user is idle. However, I do not want javascript to be executed, I just want it to be in the browser cache.
Should I use an object tag? I noticed that I can use the LINK tag, but this makes the browser think it is css, which negatively affects my performance / responsiveness.
You can load the file using the XMLHttpRequest object in JavaScript. (Aka AJAX). (then, of course, just discard the result ^^).
, .
script
window.load(function() { //your initialisation here });
.
script script, , .
script , script, . :
http://unixpapa.com/js/dyna.html
http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
, , .
, - JavaScript . javascript - , , . , // jQuery jQuery script; jQuery, jQuery . . , .
, , JS </body>. , JS , CSS .
</body>
The best way to handle external javascript is to load it after everything else on the page by placing it at the bottom of the page. Then everything that can be displayed will be displayed, and then javascript at the bottom of the page will load and compile and cache. Of course, this only works if javascipt is a library of functions that should not be executed on the middle page, in which case you are stuck in compiling and batch loading javascript independently.
Require.JS is a great library for automatic control when loading javascript.
Source: https://habr.com/ru/post/1790237/More articles:Groovy - Replacing all folders in a directory - directoryis there an open social one-sided facade? - social-networkingStrange Parsing JSON behavior in IE8 - jsonPerl scripts compile unexpectedly very slowly - perlAndroid, change phone profile - androidКак добавить поддержку интернационализации в Blogger? - javascriptПреобразование файла YAML в файл PHP - phpUsing GIT or SVN in Xcode 3/4 without a server - gitGet time_t / timeval corresponding to (local_timezone) midnight on a given date - c ++Rails / nested attributes / file _field do not appear in parameters when empty - validationAll Articles