•  · 28 friends

SOLVED:Browser caching is not working properly with nginx or apache

Hello UNA team,

I tried with both servers but the browsers are downloading the pictures each time.
For my site the timeline downloads 17 MBs each time thats too much!

Even at una.io most of the images are not browser cached.

with apache the conf is:

mod expires is enabled

ExpiresActive on
ExpiresDefault "access plus 3 seconds"
text/html "access plus 60 minutes"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType image/svg+xml "access plus 1 months"
ExpiresByType text/js "access plus 1 months"
ExpiresByType text/css "access plus 1 months"
ExpiresByType text/woff2 "access plus 1 months"
ExpiresByType application/x-shockwave-flash "access plus 30 days"
ExpiresByType text/javascript "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
ExpiresByType application/x-javascript "access plus 30 days"
ExpiresByType application/x-gzip "access plus 30 days"
ExpiresByType image/x-icon "access plus 30 days"
ExpiresByType image/vnd.microsoft.icon "access plus 30 days"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-sfnt "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

with nginx the conf is:
 location ~* \.(pdf|jpg|jpeg|gif|css|png|js|ico|svg|woff)$ {
    expires 30d;
 access_log off;
 add_header Cache-Control "public";

0 0 0 0 0 0
  • 655
Replies (3)
  • By default files which are in UNA storage are already send proper headers to be cached by browser, default setting is 30 days, you can change it in sys_objects_storage table cache_control field, however it's for public files only. Private files are cached for short period of time, the same as token_life, by default 6 minutes.

    Also I believe that more correct setting for Nginx to cache static files would be (if UNA is installed in the domain ROOT folder):

        location ~* ^(/cache_public/|/plugins_public/|/modules/|/studio/|/template/).+\.(jpg|jpeg|gif|css|png|js|ico|svg|eot|ttf|woff|woff2|)$ {
            expires 1M;
            access_log off;
            add_header Cache-Control "public";
            try_files       $uri =404;
    0 0 0 0 0 0
    • As I see now reload F5 reloads all the images with max-age=0 while in normal browsing like clicking the homepage link the images are YES cached.
      So there is no problem in caching.

      I am leaving my previous answer to be a guidance for the members who have the same question.



      When I checked at UNA site for example this image:
      it doesn't seem like it is cached.

      And request is:
      GET /s/bx_timeline_photos_processed/ay4cvkatczxt52xxnuf7kafexueezwsk.jpg HTTP/1.1
      Host: una.io
      User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0
      Accept: image/webp,*/*
      Accept-Language: tr,en-US;q=0.7,en;q=0.3
      Accept-Encoding: gzip, deflate, br
      Referer: https://una.io/
      Connection: keep-alive
      Cookie: em_cdn_uid=t%3D1559328973944%26u%3D6d12f6fdc71948ef8c0ca26e3a48b2e7; _ga=GA1.2.2132095043.1559328974; _gid=GA1.2.990492594.1559328974; em_p_uid=l:1559625371170|t:1559328984848|u:a88cf207696c475096db69c0d9616601; memberID=2159; memberPassword=c00f2e3e451b8609ede3205fb4cb67c93427c549; memberSession=tbf%2C6c.R9%3DTpah8BW%26%3FSj4bw%2CwVFDkf3
      Cache-Control: max-age=0

      Response header is:

      HTTP/1.1 200 OK
      Server: nginx
      Date: Tue, 04 Jun 2019 05:39:25 GMT
      Content-Type: image/jpeg
      Content-Length: 81877
      Connection: keep-alive
      Cache-Control: public, must-revalidate, max-age=2592000
      Accept-Ranges: 0-81877
      Content-Disposition: inline; filename="8487665900FB_IMG_1559327359772.jpg"
      Content-Range: bytes 0-81876/81877

      For a cached image like this


      there is the difference where Cache-Control: max-age=0 does not exist in the request header.

      It seems like the images like above in timeline, they are not cached also here at una, what shall we do to make them cached? Because our current timeline version is causing a lot of image files to reload each time which takes a lot of time and network cost.

      0 0 0 0 0 0
      • In Gmetrix, we get good scores except on this specific point, it's a shame.

        0 0 0 0 0 0
        Not logged in users can't 'Comments Post'.

        UNA - Social Media Software Framework