• Skip to primary navigation
  • Skip to content

Ken Morico

Marketing, Dev, Blogging, & Consulting

  • Blog
  • Podcast
  • Digital Marketing Books
  • Hire Me
  • Shop
    • Remote Sessions
    • In-Person Sessions
    • Books
    • Cart
    • Checkout
    • My Account
  • Contact
  • Show Search
Hide Search
You are here: Home / Dev & Design / No-cache Files with WordPress Multisite

No-cache Files with WordPress Multisite

February 10, 2012 by Ken Morico Leave a Comment

Creating a WordPress Multisite for a client I came across an issue when trying to prevent flash files (.swfs) from being cached (stored by the browser).

You can’t use normal Apache .htaccess files when serving files from within WordPress multisite because they get funneled through a PHP file, located in wp-includes/ms-files.php. You can check for any filetype, I checked for .swf files. Here’s my modified code:

$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
$etag = '"' . md5( $last_modified ) . '"';
header( "Last-Modified: $last_modified GMT" );
header( 'ETag: ' . $etag ); /* no cache swf files - K.Mo*/
if(preg_match("/.*\.swf/i", $file)) {
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header( 'Cache-Control: max-age=0, no-cache, no-store, must-revalidate');
header( 'Pragma: no-cache');
}
else {
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
}

You’ll need to check if WordPress gets updated because this file is part of the core WordPress insall and will liekly be overwritten when there’s an update. I’ll keep this page updated if there’s a better way to accomplish this task.

Share this:

  • Facebook
  • Twitter
  • LinkedIn
  • Pocket
  • More
  • Print
  • Reddit
  • Tumblr
  • Pinterest
  • Telegram
  • WhatsApp
  • Skype

Filed Under: Dev & Design Tagged With: Web Development, WordPress

About Ken Morico

Award-winning developer - Web | Mobile | Social. Entrepreneur.
I blog / podcast #dev #marketing #seo. I care.
Follow: YouTube · Twitter · Facebook · Instagram
Join VIP Email List / Subscribe · Need Help?

Reader Interactions

I care about what you have to say. Comment now... Cancel reply

Copyright © 2019 by Ken Morico · Privacy Policy · Terms and Conditions · Log in

  • Blog
  • Podcast
  • Digital Marketing Books
  • Subscribe
  • Hire Me
  • Shop
  • Cart
  • Contact