Reputation: 2851
I'm working on my first website right now, and when I'm updating a file (uploading the newest version to the server), for example the stylesheet or a .php
file, and I try to load the page halfway through it being uploaded/changed, I get a blank screen or broken CSS. Sometimes the cache has to be cleared for the correct stylesheet to load.
When pushing updates to users, how can this be prevented?
Upvotes: 4
Views: 328
Reputation: 1580
You can also append time Stamp to your file name so each time you refresh you get unique file
<script src="../assets/js/header.js?rndstr=<?php echo getCurrentTimeStamp();?>"></script>
function getCurrentTimeStamp(){
return date('Y-m-d G:i:s');
}
Upvotes: 0
Reputation: 1622
We've all been there and done this. Although the question probably isn't a good fit for Stack Overflow, there is a chance it'll remain here and other folks will find it. With this in mind here's an example workflow I use and some tips:
My typical workflow when working on websites is as follows:
develop
branch.git merge develop --no-ff -m "message"
Upvotes: 0
Reputation: 628
Regarding the .php file updates, the users should just receive the new responses from the updated files. In respect to the CSS, I'd suggest trying some JavaScript via jQuery.
Either way, it is good practice to not work on a live version of a website, but in a "sandbox" copy of it saved on your local machine or another folder on the server and after you've achieved the desired features, upload the files at night or when your website has minimal traffic.
Upvotes: 0
Reputation: 12236
One way to do this is with "cache busting". Everytime you make changes to your .css
or .js
file you rename the file.
style_v1.0.css // Release 1.0
style_v1.1.css // Release 1.1
style_v2.0.css // Release 2.0
Or do it after the filename:
style.css?v=1.0 // Release 1.0
style.css?v=1.1 // Release 1.1
style.css?v=2.0 // Release 2.0
Upvotes: 7