Disable Browser Cache

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by lmswimx2, Jun 26, 2014.

  1. lmswimx2

    lmswimx2 New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I've tried every piece of PHP code to disable browser caching, however, none of them worked. I don't know how to reload the css or js files from my browser after I update them. Unless I delete my browser history, I cannot make it look like it's suppose to after I upload the updated css files. Please help!!!
     
  2. Dead-i

    Dead-i x10Hosting Support Ninja Community Support

    Messages:
    6,084
    Likes Received:
    364
    Trophy Points:
    83
    Have you tried using the HTML <meta> tags on your HTML page to stop browser caching? :)

    [Moved to Programming, as this is not directly hosting-related]
     
  3. lmswimx2

    lmswimx2 New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I've tried meta html code and header php code

    I've done
    <meta http-equiv="Pragma"content="no-cache">
    but it didn't work

    For example, if I use google chrome and i go to the site. Then i upload a new css file. The i go back to google chrome and i load the site again, it'll still load the old css file, a.k.a. browser cache. However, if I open it in incognito mode in google chrome, it will load the new css file.
     
    Last edited: Jun 26, 2014
  4. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    In general, you don't want to disable browser cache for elements that should be static in a production environment. (And, really, you don't want to be doing development in a production environment either. In a local dev/test environment, you can globally set all of the cache parameters on your web server to "total amnesia" without incurring any real costs, but on a public-facing server that would be the equivalent of saying "who needs an 8-core Xeon when we have a perfectly good 486SX/25 box lying around?") You do have some real control using .htaccess to set cache-control headers, but that won't help a lot if the asset is already stuck in cache. Locally, you can either force a refresh (Ctrl-F5 twice usually does it in Chrome; Ctrl-F5 once works in most other browsers) or selectively delete your site (and your site only) from your history. In production, one would normally use a versioned file name to ensure that other users get the changes immediately without a refresh.
     
  5. leafypiggy

    leafypiggy Manager of Pens and Office Supplies Staff Member

    Messages:
    3,819
    Likes Received:
    163
    Trophy Points:
    63
    Or, do something like file.css?12389123 when you include it in development. where the numbers are randomly generated from PHP. This will ensure it loads an uncached version every time.
     
    • Like Like x 1

Share This Page