Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm trying to increase the pagespeed of our website ubercore.co. I'm using PageSpeed Insights for Chrome extension to analyze the pagespeed. It has suggested me to "Leverage browser cache". This is where I'm stuck.

I've tried some modifications to .htaccess file like this:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

and get nothing.

Later did some research and found that .htaccess is only for Apache server. Correct me if I'm wrong.

But, when I see the header response of our webpage found that the server is nginx. Then why my host has the .htaccess file in web root? I'm confused.

What I need in short: How to cache static contents for this site?

Useful links: Nginx wiki

Update 1:

Here is a screenshot of what I have, server is nginx: Respnonse headers

My question is simple, I need to cache all static content given the environment.

Update 2: As suggested by dan found that the server is indeed Apache not nginx. I don't really understand it but let it be it's off topic.

Now my problem:

Server software : Apache/2.4.7 (Unix)

Need : .htaccess code to set browser cache expiry time.

share|improve this question
    
You should first confirm if your web host is using nginx to serve your site, or as a proxy, and if the former, then ask how you might cache content specific to nginx, which would not use a .htaccess file. –  dan Mar 5 at 3:20
    
@dan The server is nginx. But my host is a shared server and he had an .htaccess file in web root by default. I've updated the question with screenshots for you. –  Vikas Swami Mar 5 at 4:55
    
Although the header may indicate it's being served with nginx, it could be served through a proxy as well. For example, if your hosting company uses a CDN, the header might indicate ngninx when it's served through Apache. You should confirm that your site is being served with nginx, and not proxied through a CDN. If that's the case, then you should edit the question to remove all .htaccess reference in your title and question since that's not relevant. Lastly, your final sentence is not really a question at all. –  dan Mar 5 at 5:02
    
@dan Thanks for the quick response dan. If the server happens to be Apache then why my .htaccess code is not working. Btw, the non-www to www rewrite rule is working fine. –  Vikas Swami Mar 5 at 5:07
    
Again, please confirm your server, and then edit your question to be specific to that and it will be reviewed to be reopened. –  dan Mar 5 at 5:15

1 Answer 1

up vote 1 down vote accepted

You can specify your cache expiry in the vhost configuration on nginx server, for example:-

location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ {
    expires 1y;

}

You'll only be able to use location in a server block however (and not http block) but you could insert this into a separate file and then include it in each server block that requires this though.

Read up on leverage browser caching at Google.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.