Preventing Caching of CSS Files

后端 未结 6 419
攒了一身酷
攒了一身酷 2020-11-27 20:28

I am developing a simple website using PHP.

Development Configuration : WAMP

Production Configuration : LAMP

While

相关标签:
6条回答
  • 2020-11-27 20:46

    I always using httcacheclean when change something in asset files (js, css, etc)

    0 讨论(0)
  • 2020-11-27 20:49
    1. Apache (-modules) can cache ressources, but that is not your current problem.
    2. Either disable your browsercache, flush cache on reload or deliver css with modded headers. You could write a script that sets expiry header so that your browser will have to get a fresh version of your css.

    Anyhow I'm not getting the point in that. For development it's way easier to just disable your browsercache or hit Ctrl + r.

    0 讨论(0)
  • 2020-11-27 20:53

    In my php pages i usually add the current date time to the end of your css href:

    <link rel="stylesheet" type="text/css" href="style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>" />
    

    Ref : Here

    0 讨论(0)
  • 2020-11-27 20:54

    I know this is an old question, but I just came across this and had some of the same issues. Here is a quick way to not keep cache on any file:

    <link rel="stylesheet" href="css/style.css?<?=time()?>">
    

    Using the helps get the newest version each time the page is loaded.

    0 讨论(0)
  • 2020-11-27 20:55

    I used to have the same problem with my LAMP dev system, caused by a network mount. I managed to get rid of it by adding these two lines to my apache conf.

    EnableMMAP off
    EnableSendfile off
    
    0 讨论(0)
  • 2020-11-27 21:04

    I've ran across this problem a few times and usually over come the problem on production sites by calling my css like this

    <link rel="stylesheet" type="text/css" href="style.css?v=1" />
    

    When you roll out an update just change the v=1 to v=2 and it will force all of your users browsers to grab the new style sheets. This will work for script files as well. If you view source on Google you will notice they use this approach as well.

    0 讨论(0)
提交回复
热议问题