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

前端 未结 5 984
自闭症患者
自闭症患者 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:22

    Generally, loading more files incurs more overhead in HTTP than combining them into fewer files. There are ways to combine files for all kinds of content:

    • For images, use CSS sprites.
    • For javascript, compile your client-side code and libraries into one file, and minify to reduce size.
    • For css, you can do something similar to the above. hem compiles stylus into one css file, for example, and this can help organizationally as well.
    • Additionally, when you concatenate Javascript and CSS, your webserver or reverse proxy can send them in compressed form for faster page loads. This will be more efficient for larger files as there is more to gain from compression.

提交回复
热议问题