Difference between `script` and `link as=“script”` tags


Difference between `script` and `link as=“script”` tags



Additionally to the standard method of loading scripts:


http://js/script.js



I have seen people do this:


<link href="js/script.js" as="script">



Is there any difference?



Note: There's a similar What's the difference between using link and script tag to reference JavaScript source? question asking about <link href="~/Scripts/jquery-1.4.1.js" type="text/javascript" />, which is different.


<link href="~/Scripts/jquery-1.4.1.js" type="text/javascript" />





stackoverflow.com/questions/12178429/… relevant? (especiallly the comments)
– Rustyjim
Jun 29 at 16:32






@Rustyjim I found this, too, but it is an old question that came to the, at this time, correct solution that link cannot be used to load javascript which does no longer seem to be the case
– MiXT4PE
Jun 29 at 16:34






Well i also found this w3c.github.io/preload/#link-element-extensions maybe helpful :)
– Rustyjim
Jun 29 at 16:43





1 Answer
1



If that link tag had rel="preload" (or rel="modulepreload") on the it, it would indicate a preload request, which would preload, but not run, the script. Whereas of course, script loads and runs the script. But without rel, that link is invalid and has no useful effect (at least in terms of the specification).


link


rel="preload"


rel="modulepreload"


script


rel


link



If you look up link in the spec, you'll see as listed as:


link


as



as — Potential destination for a preload request (for rel="preload" and rel="modulepreload")


as


rel="preload"


rel="modulepreload"



Following the link to as attribute, it says:


as



The as attribute specifies the potential destination for a preload request for the resource given by the href attribute. It is an enumerated attribute. Each potential destination is a keyword for this attribute, mapping to a state of the same name. The attribute must be specified on link elements that have a rel attribute that contains the preload keyword. It may be specified on link elements that have a rel attribute that contains the modulepreload keyword; in such cases it must have a value which is a script-like destination. For other link elements, it must not be specified.


as


href


link


rel


preload


link


rel


modulepreload


link






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift