Jump to content

My users always have to refresh multiple times after deployment


DeX

Recommended Posts

Each time I deploy new code into production, my users call me that something doesn't work and I have to tell them to refresh their browser to get the latest JavaScript code. Sometimes I even have to walk them through a hard reload and cache deletion before it will work, is there a way to avoid this? How can I force the latest JavaScript to go out to my users on each deployment?

Link to comment
Share on other sites

Fix your caching so that it correctly indicates when and when not to refresh a resource.

 

How does it work right now? Maybe there's a site you can point us to?

It's an internal portal so you would need a login to see it. Is the caching set in the code? I'm not managing the caching at all currently, I just have the JavaScript functions and I use them. If managing the cache in the code is something I can do then I'll research that and figure out how to set it up. I didn't even know that was possible.

Link to comment
Share on other sites

Caching is set by something. Generally the server, since that's the one handling the files, but if you're passing these files through PHP code first (for some weird reason) then you'd have to be explicitly doing something about caching in there.

 

If you didn't do anything then the server is likely using Expires: it instructs the browser to not even attempt to redownload the resource until some specific time has passed. That works well... up until you change the resource, so all in all it doesn't work well.

 

What web server are you using? Are you the one who manages it?

Link to comment
Share on other sites

Caching is set by something. Generally the server, since that's the one handling the files, but if you're passing these files through PHP code first (for some weird reason) then you'd have to be explicitly doing something about caching in there.

 

If you didn't do anything then the server is likely using Expires: it instructs the browser to not even attempt to redownload the resource until some specific time has passed. That works well... up until you change the resource, so all in all it doesn't work well.

 

What web server are you using? Are you the one who manages it?

Yes, it's a rather expensive Dell server running a pile of virtual machines, one of them being my Ubuntu web server I'm using for this. It sounds like I can change a setting on the server each time I do a deployment.

Link to comment
Share on other sites

Ubuntu probably means you're using Apache for the web server. (Or is it nginx?) Can you edit the virtualhost configuration? Are you using .htaccess files?

 

And you should verify the caching thing I assumed first. Open up your browser's developer tools, look for a "network"-type thing that shows page requests, make sure it's enabled or activated or whatever so that it's working, then load up a page from the intranet site. The tool should then show you information about each page that was requested, including the Javascript and CSS files. Pick one of those. Somewhere in the details will be a list of the request and response headers - what are they?

Link to comment
Share on other sites

Ubuntu probably means you're using Apache for the web server. (Or is it nginx?) Can you edit the virtualhost configuration? Are you using .htaccess files?

 

And you should verify the caching thing I assumed first. Open up your browser's developer tools, look for a "network"-type thing that shows page requests, make sure it's enabled or activated or whatever so that it's working, then load up a page from the intranet site. The tool should then show you information about each page that was requested, including the Javascript and CSS files. Pick one of those. Somewhere in the details will be a list of the request and response headers - what are they?

I'm using Apache2.

I can edit anything I like.

I am using .htaccess for some URL rewriting.

 

Here is what I got:

Request URL:https://development.xxxxxxxx.com/javascript/home.js?version=2
Request Method:GET
Status Code:200 OK (from cache)
Remote Address:208.118.xxx.xx:443
Response Headers
Accept-Ranges:bytes
Content-Encoding:gzip
Content-Length:11536
Content-Type:application/javascript
Date:Mon, 19 Dec 2016 19:02:39 GMT
ETag:"1a262-543cb2754e292-gzip"
Last-Modified:Fri, 16 Dec 2016 18:58:20 GMT
Server:Apache/2.4.18 (Ubuntu)
Vary:Accept-Encoding
Request Headers
Provisional headers are shown
Accept:*/*
Referer:https://development.xxxxxxx.com/home.php?quote=58534
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Query String Parameters
view source
view URL encoded
version:2

I put version 2 at the end attempting to fool it into thinking it was a new file.

Link to comment
Share on other sites

It sounds as if your main problem is with Javascript files. Are you storing "data" in those files? If so, the data should be captured dynamically (e.g. AJAX call) instead of hard-coded in a JS file.

 

Also, while Requinix is giving you the right answer, there is a very simple "hack" that will solve this problem. Change the extension of your JavaScript include files to a file type that the server will know needs to be retrieved every time - e.g. php, aspx, etc. Those pages should not be cached. A Javascript fiel included with a script tag does not have to have a js extension - it can be anything.

<script src="myjavascript.php"></script>

However, it also means those pages will be sent to the parsing engine each time. Not exactly efficient, but for an internal site it probably would have no impact.

 

Another hack, which may work, is to put a random parameter at the end of the URL

 

<script src="myjavascript.js?randomkey=12345"></script>

 

Again, these are hacks to provide a quick and dirty temporary solution until you can configure and test the server settings.

Edited by Psycho
Link to comment
Share on other sites

It sounds as if your main problem is with Javascript files. Are you storing "data" in those files? If so, the data should be captured dynamically (e.g. AJAX call) instead of hard-coded in a JS file.

 

No. For example, I use bootstrapDialog as a framework for loading lightboxes and the Javascript creates the lightbox HTML. I added some Javascript to put a checkbox in the lightbox and I kept getting calls from the users they couldn't see the checkbox. Some of them were fixed with a refresh but 2 others I had to do a hard reload of the page. 

 

This also happens with CSS files, if I add some styling, they often won't see it without a refresh or hard reload. Most recently this was something as simple as bolding some text and right-aligning it. That was all, but users never got the latest styling so they were complaining about how it looked.

Link to comment
Share on other sites

This also happens with CSS files, if I add some styling, they often won't see it without a refresh or hard reload. Most recently this was something as simple as bolding some text and right-aligning it. That was all, but users never got the latest styling so they were complaining about how it looked.

 

I've used the same hack(s) for css files as well. :)

Link to comment
Share on other sites

We've had this issue in the past with a system I help maintain. Adding a URL parameter on each update wasn't really feasable as the system is kind of a hodge-podge of scripts all with their own set of <script> tags to pull in various resouces.

 

What I did was configure the server (IIS in my case) to add a 3-hour limit to the cache time. Since the system is mostly just used during working hours this works well as the caches expire over night and everyone gets fresh copies in the morning including any updates made that night.

 

Adding a limit to the cache is done by either including a Cache-Control header with the max-age specifier which indicates the length of time the cache is valid in seconds or an Expires header with the date when the resource should be re-requested.

 

For apache you can add both headers using mod_expires and a configuration like:

<FilesMatch "\.js$">
    ExpiresActive On
    ExpiresDefault "access plus 5 minutes"
</FilesMatch>
Or you can add the Cache-control header with mod_headers with:

<FilesMatch "\.js$">
    Header set "Cache-control" "max-age=300"
</FilesMatch>
Edited by kicken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.