1

I have put the cache clear code in a .cfm page for security reasons. The cache clear code is

<cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">
<cfheader name="Pragma" value="no-cache">
<cfheader name="Expires" value="#GetHttpTimeString(Now()-1)#">

Now for every request it fetching all the JavaScript, CSS and image files from server which decrease the speed of my site. Is there any way in ColdFusion or JavaScript to keep the JavaScript, CSS and image files in cache to increase performance?

Deepak Kumar Padhy
  • 4,128
  • 6
  • 43
  • 79
  • 1
    Remove the headers ? oO – Virus721 Jul 30 '13 at 13:43
  • @Virus721 I can not remove the headers for security reason. – Deepak Kumar Padhy Jul 30 '13 at 13:46
  • What do you mean by security reason ? – Virus721 Jul 30 '13 at 13:48
  • @Virus721 want to prevent page caching. – Deepak Kumar Padhy Jul 30 '13 at 13:50
  • Ho i see you want to cache everything but HTML. Well i've an idea. Make all your HTML pages .php pages. This way the browser will re-download them everytime a user loads the page since the HTML is generated on the fly, the file will be considered modified. – Virus721 Jul 30 '13 at 13:57
  • 1
    @Virus721: No. It makes no difference to caching whether the file extension is `.php` or `.html` or whether the files were dynamically generated or not. – Bergi Jul 30 '13 at 14:14
  • So...you want to cache the page...but you don't want to cache the page? – Scott Stroz Jul 30 '13 at 15:18
  • 3
    The CF pages and the images/scripts/styles all come in separate requests, so you can set different headers on all of them, and they won't affect each other - so turning off cache on your .cfm page will not turn off cache on your images. Have you confirmed that you're not caching the static files by watching the network requests and the headers on those files? – Joe Enos Jul 30 '13 at 16:09

1 Answers1

0

(Assuming you're on Apache) Enable your mod_expires and customize your cache conditions in your .htaccess file.

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault “access plus 1 second”
    ExpiresByType text/css “access plus 7 days”
    ExpiresByType image/jpg “access plus 7 days”
</IfModule>
XaxD
  • 1,429
  • 14
  • 27
  • Yes we are using Apache, Could you please explain me in which file i should put this code. – Deepak Kumar Padhy Jul 31 '13 at 06:20
  • this script would go in your .htaccess file. If it does not work seek further help from this previous answer: http://stackoverflow.com/a/11622555/2623144 – XaxD Aug 01 '13 at 02:33