dou2347 2011-10-26 01:47 采纳率: 0%
浏览 75
已采纳

使用PHP动态禁用Javascript / CSS的缓存?

I've coded an option called 'devmode' in my web app, which basically means 'no caching'. The app normally outputs an automatically minified (and aggregated) version of the Javascript and CSS, but the devmode option overrides this.

However, we still have the browser cache. So, without further ado, how can I disable caching of ALL components on a page if a certain PHP boolean is true?

Cheers

Edit: might interest you to know that I'm running Apache, and one idea I had was to force .js and .css to be parsed as PHP (which is straightforward), and somehow 'inject' a little piece of PHP code at the start of each.

  • 写回答

2条回答 默认 最新

  • douji6896 2011-10-26 01:55
    关注

    A "quick and dirty" approach for debugging/developing, you could call all components in your HTML with a random (or time-based) query-string. For instance:

    <img src="logo.png?uniqecall=20111026035500" />
    

    , which would look like this in your PHP code:

    print '<img src="logo.png?uniqecall=' . date("YmdHis") . '" />';
    

    etc...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?