coool
coool

Reputation: 8297

would concatenating javascript files prevent individual files from caching?

I am trying to weigh the advantage of concatenating over using js loaders. Say If I have page 1 with javascript file 1 & 2 and I concatenate both of it and on the second page I have javascript file 2 & 3 and I concatenate both of it and send it ..would this prevent caching of 2nd javascript on the client side. if i had send the scripts on page 1 as js1 & js2 then js2 would have got cached on the client side and when page2 comes in it would not request js2 since it is got it already. so it will request only js3.

so which is a better approach.

Thanks

Upvotes: 2

Views: 90

Answers (1)

Andrew Barber
Andrew Barber

Reputation: 40149

It would not prevent caching, but it would cause needless over-caching.

You would end up with two cached js files, each of which contained a large block of the same code.

You should keep the script files separate, and allow the client to cache them separately.

Upvotes: 1

Related Questions