Hi people,
on all the "speed up your website" sites and books they always tell us to minimize HTTP requests at all costs. This is fine and nice but what if that means that on every page you have to reload 120kb again and again and again because the user cache is empty?
If i use 5 js files on every page of my website, wouldnt it be better to put them in one file and load this file on every page instead of putting them together with all other variable files in one big file and save one HTTP request. From which point or filesize on is it ok "cache" a file and have another HTTP request?
I give you an example of 3 pages when i use only one HTTP request for one minifed JS file per page:
- jquery, jquery ui, thickbox, lavalamp menu => together minified in one file = 300kb
- jquery, jquery ui, cycle plugin => together minified in one file => 200kb
- jquery, jquery ui, galleria plugin => together minified in one file => 250kb
And now the other possibility with always 2 HTTP requests: One File consisting of jquery and jquery ui => 150kb, lets call it "jui.js" for now
- jui.js, thickbox, lavalamp = again 300kb in the beginning, BUT now jui.js is cached for the other 2 pages
- (jui.js is cached now so not loaded), only cycle plugin => only 50kb to load but one more HTTP request as i load jui.js and the cycle plugin seperately.
- (jui.js is already cached), only load galleria plugin => only 100kb more to load but again 2 HTTP requests where one request is already cached
So at which point or Kb size is it ok to have another HTTP request on a normal "responsive" web server?
Does anybody have any best practices or is it just "Minimize HTTP requests at all costs!"?
(I hope i made myself clear :) And i will vote up people as soon as i have some points!)
EDIT:
It is basicly a simpler question: How long does a extra HTTP roundtrip for a cached js file need? If the http request is slower than the time i would need to download the extra non cached parts on every page, then i would put everything in 1 big file on every page(1 different big file on every page).
If the HTTP request for a cached js file is nearly nothing, then i would split the parts that every page needs in an extra js file(minifed of course) and include the dynamic parts of every page in differend(again minified) js files.
So if on most pages i need a 100kb extra(the dynamic part), how do i test the time for a cached HTTP request? Are there any numbers, did anybody test something like this already?
Thanks for the great answers already!