Can I load javascript code using <link> tag?

前端 未结 8 1512
情歌与酒
情歌与酒 2020-12-02 20:20

Can I load javascript code using tag in my website ?

For example I have a javascript file, test.js, which contains the simple

8条回答
  •  情歌与酒
    2020-12-02 21:17

    Modern browsers support the preload keyword, which is used to preload various resources, including scripts. From MDN:

    The preload value of the element's rel attribute allows you to write declarative fetch requests in your HTML , specifying resources that your pages will need very soon after loading, which you therefore want to start preloading early in the lifecycle of a page load, before the browser's main rendering machinery kicks in. This ensures that they are made available earlier and are less likely to block the page's first render, leading to performance improvements.

    A simple example might look like this (see our JS and CSS example source, and also live):

    
      
      JS and CSS preload example
    
      
      
    
      
    
    
    
      

    bouncing balls

提交回复
热议问题