Re:Ask HN: Include JavaScript via PHP or HTML?
by alttab on Wednesday March 10, 2010 @11:42PM
(#1182993)
In a second and real answer to your question, the file should only require the second HTTP request the first time. Any subsequent inclusions of that file won't go to the server to get it.
The downside is it makes each page bigger. If isn't a real small javascript file, you are adding all those bytes to each request. In this case, it would require more bandwidth to transfer the entire page at the same speed.
Re:Ask HN: Include JavaScript via PHP or HTML?
by clusterfu_k on Thursday March 11, 2010 @12:00AM
(#1183035)
if the time it takes to download the slightly page is less than the time it takes for the second request for a separate js file on average (including when cached), then i would be in the clear?
I understand why loading the page would be faster if it was all in one file. Also, I realise that this would not allow for the dynamic page to be cached properly for future use, but I have tested and the effects of the lack of caching are minimal.
So the question is what are the downsides of doing it this way?