Mehdi
Mehdi

Reputation: 373

Laravel Forge (Nginx) Gzip and browser caching + SSL

I'm trying to improve the browser caching as well as using gzip compression. Within my investigations I came across sources saying that you should not enable compression when SSL is enabled.

I came across this nginx settings for my setup. https://gist.github.com/reedmaniac/adfa2740323d08de25bd

Could anyone advise whether I can follow the above setting blindly, or I need to leave the default Forge setting?

Here is the the google developer page speed result on my website which indicating I need to leverage browser caching and compression: https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.itutorialist.com

Upvotes: 2

Views: 2312

Answers (2)

Mahen Nakar
Mahen Nakar

Reputation: 394

here is my setting in nginx.conf forge inside serve

# browser caching of static assets
    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
        expires 7d;
    }

    server_tokens off;

    #GZIP
    # Enable gzip compression.
    gzip on;

    # Compression level (1-9).
    # 5 is a perfect compromise between size and CPU usage, offering about
    # 75% reduction for most ASCII files (almost identical to level 9).
    gzip_comp_level    5;

    # Don't compress anything that's already small and unlikely to shrink much
    # if at all (the default is 20 bytes, which is bad as that usually leads to
    # larger files after gzipping).
    gzip_min_length    256;

    # Compress data even for clients that are connecting to us via proxies,
    # identified by the "Via" header (required for CloudFront).
    gzip_proxied       any;

    # Tell proxies to cache both the gzipped and regular version of a resource
    # whenever the client's Accept-Encoding capabilities header varies;
    # Avoids the issue where a non-gzip capable client (which is extremely rare
    # today) would display gibberish if their proxy gave them the gzipped version.
    gzip_vary          on;

    # Compress all output labeled with one of the following MIME-types.
    gzip_types
      application/atom+xml
      application/javascript
      application/json
      application/ld+json
      application/manifest+json
      application/rss+xml
      application/vnd.geo+json
      application/vnd.ms-fontobject
      application/x-font-ttf
      application/x-web-app-manifest+json
      application/xhtml+xml
      application/xml
      font/opentype
      image/bmp
      image/svg+xml
      image/x-icon
      text/cache-manifest
      text/css
      text/plain
      text/vcard
      text/vnd.rim.location.xloc
      text/vtt
      text/x-component
      text/x-cross-domain-policy;

Hope this is will be helpful to everyone

Upvotes: 1

Bardi Harborow
Bardi Harborow

Reputation: 1888

You seem to have GZIP configured correctly. Your current issue is that you are not setting an appropriate Cache-Control header, and that your images are very poorly optimised.

Upvotes: 0

Related Questions