3 ms·
moving inline script and CSS into external files By reducing the number of files that are referenced within a web page, you reduce the time required for these
by userbinator 12y ago
moving inline script and CSS into external files
By reducing the number of files that are referenced within a web page, you reduce the time required for these requests to be sent, and for their responses to be received.
Aren't these exact opposites of each other? I suppose which direction to take depends on the bottleneck - if request latency is high, it might be better to put everything inline, but if the bottleneck is parsing then separating things into external files could have the advantage.
- asolove 12y agoHaving js and ces in single, cacheable external files will speed up later page loads on the site.
- protonfish 12y agoOnly to a degree, and then it starts making things worse. If your browser has to parse 20MB of CSS and JS (99.9% of which is not needed) to load a simple web page, it will be much slower than including only the necessary includes.
- asolove 12y agoYup. Once you have harder problems, you need harder solutions and you'll want to create a layered build with one cacheable file for common things used everywhere and then one separate file for each page's specific things. RequireJS and other front-end build tools are good at this: http://requirejs.org/docs/1.0/docs/faq-optimization.html http://requirejs.org/docs/1.0/docs/faq-optimization.html
- theandrewbailey 12y agoThat advice isn't that contradictory. Putting CSS and JS into external files increases number of files, but decreases page size. (win for page size) External files can be cached. (win for page load times) Therefore, navigating to different pages that reference the cached external files shortens load times. The warning is don't go overboard. Separate them, but no more than necessary.