Multiple external JavaScript files using one script tag

前端 未结 3 1873
星月不相逢
星月不相逢 2020-12-18 10:36

I have seen on some websites they have one script tag but call multiple JS file e.g.

3条回答
  •  Happy的楠姐
    2020-12-18 10:51

    That loads a single JS file. The URLs just has multiple things that look like filenames in it.

    There is a strong probability that the single JS file is built from multiple files by a server side script. If so, that is just a simple matter of…

    1. parsing the filenames from the URL (split on commas)
    2. sanity checking them
    3. concatenating the files into the response

    (and giving it a suitable Content-Type header).

    It is inefficient to do that for every hit though, so make sure you implement sane caching. Both with HTTP response headers and on your server.

提交回复
热议问题