w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why create script tag via Javascript, instead of using defer or async script tag attributes?

I can think of one uncertain (no. 1) and two likely reasons (no. 2 and 3):

[Edit] But reasons 2 and 3 are moot points — Disqus could simply do this despite of my reasons 2 and 3:

<script src="http://the_disqus_shortname.disqus.com/embed.js"
async>

[/Editi]

  1. (Perhaps old browsers that doesn't understand the async attribute completely ignore the whole <script ... async> tag? Instead of ignoring only async and loading the script synchronously?)

  2. Perhaps Disqus would like to be able to genereate the embedded script dynamically, or redirect to different scripts, depending on website settings (although it seems as if Disqus currently always redirects to the same embed.js script always). Without having users reconfigure their Disqus code.

  3. Using a redirect allows Disqus to tell the browser to cache the-scripts-that-is-redirected-to for a long amount of time, but at the same time makes it possible to quickly redirect to another script. At the cost of 1 redirect per download / fetch-from-browser-cache. This was suggested here: http://stackoverflow.com/a/10098250/694469





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.