Search code examples
phpweb-applicationsftpfilezilla

Push website updates without affecting the user


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?


Solution

  • 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