Have been studying the use of async
and defer
in script tags. Given the following...
async - Allows the rest of the html to parse, while the JS script is being loaded. Once the script is completely loaded then the html parser is paused to execute the script. However, note that the order of loading can't be controlled.
defer - Also allows the rest of the html to parse, however the loaded js is only executed once the html parsing is complete.
So, if you can afford to show your html without loading your js script first... use
async
. If more than one script is involved and the order they are loaded matters then usedefer
. On the other hand, if your scripts MUST be loaded first (and can't be rewritten to allow the html to parse first) then just load the script without usingasync
ordefer
in the header.
How would this fit with modern frameworks like AngularJS... since, delaying their loading results in an error. Any pointers would be appreciated.