Home / Business Growth / No-cache Files with WordPress Multisite

No-cache Files with WordPress Multisite

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

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.


See more articles:

Published:

Recent Newsletter Issues:

See All Newsletter Issues & Subscribe >

Ken Morico

Consultant, Investor / Trader, and Entrepreneur

I’ve advised Fortune 500 companies, celebrities, startups, and high net-worth individuals while empowering millions online with insights on my blog and social media.
Read Ken’s Story


Leave a Reply

Your email address will not be published. Required fields are marked *