Page 1 of 1

External js or inline?

PostPosted: Sat May 28, 2016 5:46 pm
by fkapnist
Why does Google recommend external js but uses inline js for google.com? Look at the source of google.com. They found that in their particular case inlining works better (they practice the opposite of what they preach). The "expert" suggestions to use external js arouse during “the first age of the web” when scripts blocked rendering. Today PCs have gigabytes of RAM memory and modern browsers execute as soon as possible. In fact, more and more programmers are saying that it's best to inline all scripts, styles and templates - unless your script is extremely long or the same script is shared by several pages. One reason for this is because javascript does not support multi threading. The computer must wait for the long script to finish before continuing. This could lead to the dreaded "not responding due to long running script" error message. The best way to avoid this is to break up long scripts into a series of short ones connected with setTimeout() functions, to allow the PC to regain control or "breathe" between scripts. The only problem is that external js cannot contain <script> tags and therefore cannot be easily broken into smaller chunks. To add to the confusion, most mobile devices simply don't have much RAM to begin with and will slow down or freeze when executing very long scripts..... So does anyone know how to deal with the long running script problem?

:roll:

.