-1

I am working on the performance optimization of my website but it is very difficult to match all the suggestion of the google because most of the suggestion is based server side in nginx because .htaccess will not work on the nginx.

Please guide me on this for nginx and apache so that i can optimize my website.

Below are the steps which i have implemented.

Apache

  1. Mod_expires
  2. Mod_headers
  3. Enable compression
  4. Leverage browser caching

Reference Link : Leverage browser caching, how on apache or .htaccess?

Nginx

I have not found any revent info on blogs.

Please let me know to optimize the websites

Community
  • 1
  • 1
Manoj Chowrasiya
  • 970
  • 1
  • 13
  • 32

1 Answers1

2

You can enable browser caching for static files that don't change time to time. Here's some example for nginx:

# Feed
location ~* \.(?:rss|atom)$ {
  expires 1h;
  add_header Cache-Control "public";
}

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
}

Some explanation:

You need to use location directive to leverage browser caching mentioning specific types of files you want to cache.

expires - sets the caching time. add_header - to add caching header to the browser.

You can also turn on gzip compression for your server by adding: gzip on;