0

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 Answers 2

1

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...

Sign up to request clarification or add additional context in comments.

Comments

1

.htaccess

RewriteRule ^no-cache/(.*?)$ no-cache.php?file=$1 [QSA,L]

no-cache.php

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
readfile('static/'.$_GET['file']);

Assuming you won't hack yourself :)

3 Comments

Heh, this solution seems more hacky than the "quick and dirty" one :D
it is easier to write /no-cache/dev.js then /static/dev.js?id=123456789, plus you have some control with php ;)
True you have some control, but when the actual rendering of the <script> tags is done dynamically (as in this case), it's actually (for me) easier to keep track of if it's all done in one place. So I guess either solution is good depending on the circumstance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.