Howcome I don't have to clear cache when I move code to production?

I've had this question for a while now...

When I make changes to JS/jQuery code and run the code locally on my laptop, I sometimes need to clear the cache to see the changes.

I have both minified and non-minified version of JS files.

When I move the code to our Production, I don't ask the users to clear their cache.

Howcome users don't have to clear their cache when I move code to Production? why do I need to clear cache only when I'm developing?
LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
When the users' systems are powered up in the morning and also when their browsers are started from scratch at the beginning of the day, their browser caches will be clear.  The issue can't occur in this situation.
Julian HansenCommented:
First question is: how do you know they don't have to clear their cache?

Cached JS / CSS is a common problem which is why many systems work on a principle of versioning their scripts / stylesheets by adding a parameter to the URL
?ver=123
or ?ver=time()

If you look at angular code when you build it the minified scripts are always suffixed with a new GUID to make them unique.

As for users cache clearing because they shut their browsers down - that is totally incorrect.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technical NinjaCommented:
Hi Camillia,
Browsers use cache to improve overall performance of browsing experience. They check filesize and other attributes to figure out if they should use the file from the cache or request a fresh file from the server. Browser caches are not designed nor intended to be frequently invalidated.

What we do as developers is bit different than normal users. In our case, we are repeatedly visiting (sometimes more than 100 times a day) a same site and possibly during each visit(not the JavaScrpt framework libraries) we might have a different JavaScript code written on the page or in external js files and sometimes browsers are not able to differentiate due to various factors(file size change is minimum, or you are refreshing the page within a minute).

For your end users if you keep deploying new files every now and then, it will happen. Also, for production servers, the date difference will invalidate local cache.

Microsoft Dynamics CRM used to face this a lot hence they came up with a simple trick, every time they change common files they change the version number(which is a suffix in the file name). So even if the old files are there in the cache, they are never used by the new pages and eventually are cleared off.

Regards,
Chinmay.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

CamilliaAuthor Commented:
Thanks, guys.

First question is: how do you know they don't have to clear their cache?
Yes, I don't know for sure.

Question

Cached JS / CSS is a common problem which is why many systems work on a principle of versioning their scripts / stylesheets by adding a parameter to the URL
?ver=123
or ?ver=time()

How would versioning help in clearing the cache?
Dr. KlahnPrincipal Software EngineerCommented:
I must respectfully disagree with Julian's comment regarding browsers and cache.  Every browser I have encountered starts up with nothing in its cache, and builds the cache as it continues running.
Jeffrey Dake Senior Director of TechnologyCommented:
Browsers cache pages/files by file names. By adding an extra parameter of the version of the url, the browsers then grab a fresh version of the page, because it thinks it is brand new. You could notice the same problem with images. That is why I tell my developers to never change a image file. If they need a new image use a new file name to guarantee the browsers are not serving up a cached/old version.
Julian HansenCommented:
@Dr Klahn,

You can disagree as much as you like that is not how it works.

1. Open Chrome
2. Open the Console (F12) and go to the network tab
3. Browse to a site - say to this page
4. Close Chrome and repeat the above
5. Check the Size column in the Network tab - look for (from disk cache)

Here is a screen grab of the above.
Chrome loaded clean - went to this page and see the disk cache loads. Chrome screen grab
it_saigeDeveloperCommented:
Agreed with Julian.  But Dr. Klahn is also, somewhat, correct.  Browser will start with nothing in their cache if you have cleared the cache before opening or configured the browser to automatically clear cache on shutdown.

However, by default, all browsers will employ some sort of caching.

-saige-
Julian HansenCommented:
if you have cleared the cache
If you clear your cache the problem goes away - irrespective of whether you restart the browser or not.
CamilliaAuthor Commented:
Thanks. Let me read.
CamilliaAuthor Commented:
Thanks. I have another question but I'll open another thread. This helped a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.