Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glueckpress/cc3c72cf08b7bd01bc161a5ddb3a661e to your computer and use it in GitHub Desktop.
Save glueckpress/cc3c72cf08b7bd01bc161a5ddb3a661e to your computer and use it in GitHub Desktop.
[WordPress][WP Rocket] Add browser caching rule to .htaccess; example: zero browser caching for PDF files
<?php
/**
* Zero browser caching for PDF files.
*/
add_filter( 'rocket_htaccess_mod_expires', function ( $rules ) {
$rules .= '# Expires headers for PDF' . PHP_EOL;
$rules .= '<IfModule mod_expires.c>' . PHP_EOL;
$rules .= 'ExpiresByType application/pdf "access plus 0 seconds"' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL . PHP_EOL;
return $rules;
} );
@tanmoy-web
Copy link

I am using wp rocket pro plugin for my website, but my website showing leverage browser caching warning. I am trying to fix these issues but do not work. so, what should I do now?

My website here: https://wcblogs.com

@glueckpress
Copy link
Author

@tanmoy-web The best advise I have is turn to the WP Rocket documentation and/or contact their support. Also, that particular warning doesn’t always mean something is wrong on your site; it could also be a third-party script that is loaded on your site but it’s origin server doesn’t support browser caching.

@tanmoy-web
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment