load scripts asynchronously

前端 未结 19 1240
粉色の甜心
粉色の甜心 2020-11-22 12:01

I am using several plugins, custom widgets and some other libraries from JQuery. as a result I have several .js and .css files. I need to create a loader for my site because

19条回答
  •  眼角桃花
    2020-11-22 12:28

    Have you considered using Fetch Injection? I rolled an open source library called fetch-inject to handle cases like these. Here's what your loader might look like using the lib:

    fetcInject([
      'js/jquery-1.6.2.min.js',
      'js/marquee.js',
      'css/marquee.css',
      'css/custom-theme/jquery-ui-1.8.16.custom.css',
      'css/main.css'
    ]).then(() => {
      'js/jquery-ui-1.8.16.custom.min.js',
      'js/farinspace/jquery.imgpreload.min.js'
    })
    

    For backwards compatibility leverage feature detection and fall-back to XHR Injection or Script DOM Elements, or simply inline the tags into the page using document.write.

提交回复
热议问题