• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Thomas Griffin

Be a better leader

  • About
  • Newsletter
  • Articles
  • Business
  • Favorites
  • Contact

How to Leverage Browser Caching in WordPress via .htaccess

Thomas Griffin Avatar
written byThomas Griffin
last modifiedJune 11, 2021

One of the best ways to improve the speed and performance of your WordPress site is to leverage browser caching.

By leveraging browser caching, you can reduce the number of HTTP requests that the server needs to process, thus reducing loading times and improving website performance. And as an added bonus, when you leverage browser caching, you improve your scores on Core Web Vitals and other pagespeed tools!

In order to leverage browser caching appropriately, you need to modify the .htaccess file for your site.

How to Leverage Browser Caching in WordPress via .htaccess

Finding and Modifying .htaccess

While it may seem daunting, modifying the .htaccess file is quite simple. You can access your .htaccess file through cPanel by clicking on the File Manager. Make sure you are in the web root folder and that you have the “Show hidden files” option toggled on.

If you don’t have cPanel, you can simply create a new .htaccess file in the root of your WordPress install. The root folder is the same folder where the wp-config.php file is found.

Don’t Want to Mess with Code?

Code can be scary, but leveraging browser caching in WordPress via .htaccess doesn’t have to be. Get the WP Rocket plugin, and it will handle it for you automatically! Click here to get WP Rocket!

Pasting in the Directives to Leverage Browser Caching

Open up your .htaccess file and paste in the following directives at the top of the file:

## Leverage Browser Caching in WordPress via .htaccess ##
<IfModule mod_expires.c>
	FileETag MTime Size
	AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
	ExpiresActive On
	ExpiresByType text/html "access 600 seconds"
	ExpiresByType application/xhtml+xml "access 600 seconds"
	ExpiresByType text/css "access 1 month"
	ExpiresByType text/javascript "access 1 month"
	ExpiresByType text/x-javascript "access 1 month"
	ExpiresByType application/javascript "access 1 month"
	ExpiresByType application/x-javascript "access 1 month"
	ExpiresByType application/x-shockwave-flash "access 1 month"
	ExpiresByType application/pdf "access 1 month"
	ExpiresByType image/x-icon "access 1 year"
	ExpiresByType image/jpg "access 1 year"  
	ExpiresByType image/jpeg "access 1 year"
	ExpiresByType image/png "access 1 year"
	ExpiresByType image/gif "access 1 year"
	ExpiresDefault "access 1 month"
</IfModule>
## Leverage Browser Caching in WordPress via .htaccess ##

By using this code, your main static files (images, CSS, PDF’s, JS, etc.) will be cached in order to produce faster loading times for visitors in the future.

Now save your .htaccess file and view your WordPress site through Core Web Vitals and other PageSpeed tests. You are now leveraging browser caching for your site!

I hope you’ve found it easy to leverage browser caching in WordPress with this tutorial. If so, please share it with others using the social buttons found on this article.

FacebookTweetLinkedIn
Thomas Griffin Avatar
Thomas Griffin

Hey friend! I'm Thomas, and I've been in WordPress for 10+ years. I've contributed to core and created the TGM Plugin Activation class. My WordPress plugins are active on over 19,000,000 websites and include popular ones like OptinMonster, WPForms and MonsterInsights.

View my WordPress toolbox•More about me →

Reader Interactions

Leave a Reply Cancel reply

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

previous article: How to Enable HTTP Strict Transport Security (HSTS) in WordPress
next article: How to Remove Empty Paragraph Tags from Shortcodes in WordPress
Breakthrough Leadership: 5 Surprisingly Simple Qualities of Today's Exceptional Leader

Breakthrough Leadership

Great leaders share common traits that separate them from the pack. Download your copy of my signature ebook, Breakthrough Leadership: 5 Surprisingly Simple Qualities of Today's Exceptional Leader, absolutely FREE when you enter your name and email address below.

The best leaders are servants. They humble themselves so that others may be lifted up, and in doing so, they change the world.

Thomas Griffin

Footer

ThomasGriffin.com Logo

Copyright © 2010-2022 Griffin Media LLC.
All rights reserved.

Connect

Sites I Like
OptinMonsterTrustPulseWPFormsMonsterInsightsWPBeginnerEclectic TigerSyed BalkhiAwesome Motive

Misc
Don't Click HereWordPressPrivacyDisclosures Sitemap

Breakthrough Leadership: 5 Surprisingly Simple Qualities of Today's Exceptional Leader

Breakthrough Leadership

Great leaders share common traits that separate them from the pack. Download your copy of my signature ebook, Breakthrough Leadership: 5 Surprisingly Simple Qualities of Today's Exceptional Leader, absolutely FREE when you enter your name and email address below.