We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53318
    • 4 Posts
    MODX Revolution
    Windows 7


    I've got this:
    HTTP/1.1 200 OK
    Server: nginx/1.2.1
    Date: Wed, 15 Mar 2017 14:22:26 GMT
    Content-Type: text/html; charset=UTF-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: Accept-Encoding
    X-Powered-By: PHP/5.4.45-0+deb7u7
    Set-Cookie: PHPSESSID=ha1of3qb403phm23uprm09hmo6; expires=Wed, 22-Mar-2017 14:22:26 GMT; path=/; HttpOnly
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: max-age=300
    Pragma: no-cache


    And I need:
    Cache-Control: max-age=7days
    Also Google PageSpeed telling me to Leverage browser caching for:
    jpg\png\css\js



    I tried:
    to add modules to htaccess, but it's not working (maybe modules aren't avaliable, maybe nginx taking over control i don't know)

    I believe the right answer is something like this:
    # Expire rules for static content
    
    # cache.appcache, your document html and data
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
      expires -1;
      # access_log logs/static.log; # I don't usually include a static log
    }
    
    # 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";
    }

    But i don't understand where i have to place this code. They say: "place it in the block server of your site"
    Maybe someone knows where is exactly this file with this block?
    Or there's easier way?


    Please, can you help me to fix it, i'm fighting 24hours already. [ed. note: sotandr last edited this post 9 years, 7 months ago.]
      • 3749
      • 24,544 Posts
      Is it possible that you're following instructions for Apache, but you don't have an Apache server?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 53318
        • 4 Posts
        Quote from: BobRay at Mar 15, 2017, 12:15 PM
        Is it possible that you're following instructions for Apache, but you don't have an Apache server?
        Very much possible.

        I just found BD access:
        http://prntscr.com/ekcx95
        But i still don't know what to do. There's Apache, but i guess there's no modules _expired and _headers
        I don't know how to add it from there.

        There's result from test:
        Server: nginx/1.2.1
        But i don't see any nginx.cofig file in BD.



        There is plenty instruction how to add cache settings from .php but i can't find the right place.
        For ex.:
        <?
        header("Cache-control: public");
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60*60*24) . " GMT");

        Wherever i past it in index.php - i get blank screen.

        And i think i'm missing something very simple... [ed. note: sotandr last edited this post 9 years, 7 months ago.]
          • 53318
          • 4 Posts
          I found cash in MODX Panel, finally.

          When i changed options, i put
          cache.xPDOAPCCache
          instead of
          xPDOFileCache

          And i'v got text insted site...

          Please, help me to fix configuration from local host...

          And it will be the last.
            • 3749
            • 24,544 Posts
            It's not my area of expertise, but maybe someone else can help.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 44195
              • 293 Posts
              Perhaps have a look at how the microcache extra does it. It works brilliantly but not sure that you can alter TTL.
              https://modx.com/extras/package/microcache
                I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
                Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
                • 3749
                • 24,544 Posts
                I had forgotten this section I put in .htaccess a long time ago:

                ## 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 text/html "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 1 month"
                </IfModule>
                ## EXPIRES CACHING  ##


                I think you can also do it by matching file names, like this:

                <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
                  Header set Cache-Control "max-age=290304000, public"
                </FilesMatch>
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 38290
                  • 712 Posts
                  Service Workers could be utilized as an extra layer of cacheing by instructing the browser to hold onto files like the Manager JS regardless of cache headers (server configuration). I took a swing at adding service workers but unfortunately they don't work inside the Manager and I think it is because we aren't using the HTML5 doctype.

                  Worth noting, like HTTP/2, service workers require HTTPS.
                    jpdevries