Is it better to load many small JavaScript files or one large JavaScript file?

前端 未结 5 968
自闭症患者
自闭症患者 2021-02-05 13:43

I have noticed in chrome that if I load an image as a base64 string and then scroll through that part of the page it will slow down.

I have also noticed that when I navi

5条回答
  •  情书的邮戳
    2021-02-05 14:10

    Well there is a very popular concept called concatenation. The idea is to have as few HTTP requests to your server as possible. Because each request means a new connection, for which DNS lookup happens, then handshake is negotiated and then after a few more protocol-based steps, the server sends the requested file as the response.

    You can check http-archive for a list of performance best-practices.

    So yeah, you should combine all JS files into one (there are certain exceptions, like js at head and js in footer)

    This is the answer for your question-title and points 2 & 3.

    As for the other part, I am not clear about the scenario you are talking of.

提交回复
热议问题