Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Feb 2008
    Posts
    529
    Plugin Contributions
    0

    Default .htaccess cache for improved site speed?

    I added this code, from zc tutorial to my includes/.htaccess to try and improve my loading speed.

    Code:
    ## Optional caching improvements
    ## Requires mod_header and mod_deflate to be enabled within Apache
    ##################
    <IfModule mod_headers.c>
      Header unset Pragma
      FileETag None
      Header unset ETag
      <FilesMatch ".*\.(ico|jpe?g|JPE?G|gif|GIF|webp|png|swf|flv)$">
        Header set Cache-control "max-age=864000, public, must-revalidate"
        Header unset Last-Modified
      </FilesMatch>
      <FilesMatch ".*\.(html|htm|xml|txt|xsl)$">
        Header set Cache-control "max-age=7200, must-revalidate"
      </FilesMatch>
    </IfModule>
    <IfModule mod_deflate.c>
      <FilesMatch "\.(js|css)$">
        SetOutputFilter DEFLATE
      </FilesMatch>
    </IfModule>
    
    ##################
    ## Optional improvements
    ## Requires mod_expires to be enabled within Apache
    ##################
    <ifmodule mod_expires.c>
      ExpiresActive On
      ExpiresDefault A300
      ExpiresByType application/x-javascript A3600
      ExpiresByType text/css A3600
      ExpiresByType image/gif A604800
      ExpiresByType video/x-flv A604800
      ExpiresByType application/pdf A604800
      ExpiresByType text/html A300
      ExpiresByType image/x-icon A86400
      ExpiresByType image/jpeg A2592000 
      ExpiresByType image/png A2592000 
    </ifmodule>
    My google site speed test https://developers.google.com/speed/pagespeed/insights/ actually dropped my score a few points.

    Among the suggestions - optimize images, leverage cache.

    I use IH4 (last version in plugins, not the github). So vast majority of images are already optimized, no? Or maybe my originals are too large?

    I'm running the speed test on my home page which includes product photos in new and featured tabs and these are re-sized images. But google gods say they lack expiry dates.

    IH4 is storing the images in root folder /bmz_cache which has the following .htaccess:
    Code:
    # deny *everything*
    <FilesMatch ".*">
      Order Allow,Deny
      Deny from all
    </FilesMatch>
    
    # but now allow just *certain* necessary files:
    <FilesMatch ".*\.(jpe?g|JPE?G|gif|GIF|png|PNG|swf|SWF)$" >
      Order Allow,Deny
      Allow from all
    </FilesMatch>
    
    IndexIgnore */*
    
    
    ## NOTE: If you want even greater security to prevent hackers from running scripts in this folder, uncomment the following line (if your hosting company will allow you to use OPTIONS):
    # OPTIONS -Indexes -ExecCGI
    Could I/should I add the same code addition from the /includes/.htaccess to the obottom of the bmz_cache/.htaccess?

    zc 1.5.5a, Responsive Sheffiled Blue 2.0 adapted to same, IH4, many mods.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: leverage cache for improved site speed

    Couple of things. IH4 compresses the files/images at time of first loading them, so if the "page" hasn't been viewed by someone before you ran the test, then conversion time was factored into your test. That said, yes, because the bmz_cache directory tends to be placed outside of the images directory, any improvement applied to the images directory would be suited to apply to the bmz_cache directory (or "wherever" images are frequently accessed.)

    Big thing further though, once that is applied, if you plan to change the image that is stored at the "base" location, it is somewhat "locked in" until the time elapses. The way to overcome that is to reference a different base name such that it is a different file, but then back to the recreating the image(s) on first load "issue"...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by soxophoneplayer View Post
    I added this code, from zc tutorial to my includes/.htaccess to try and improve my loading speed.
    If you need to muss with .htaccess to gain speed you probably have more serious issues at play.

    Quote Originally Posted by soxophoneplayer View Post
    My google site speed test https://developers.google.com/speed/pagespeed/insights/ actually dropped my score a few points.
    Hardly the best indicator as to what is going on.

    Quote Originally Posted by soxophoneplayer View Post
    Among the suggestions - optimize images
    .
    That what IH4 does. It is the reason it exists. :)

    Quote Originally Posted by soxophoneplayer View Post
    , leverage cache.
    Also handled by IH4, but there is *better*. (see below, re: CDN)

    Quote Originally Posted by soxophoneplayer View Post
    I use IH4 (last version in plugins, not the github). So vast majority of images are already optimized, no?
    Correct, but, only after they've been accessed at least once(so IH4 can compress and cache them)

    Quote Originally Posted by soxophoneplayer View Post
    Or maybe my originals are too large?
    Super large images will only cause a slowdown on 1st access. After that the users should be receiving the compressed & cached copies.

    Quote Originally Posted by soxophoneplayer View Post
    I'm running the speed test on my home page which includes product photos in new and featured tabs and these are re-sized images. But google gods say they lack expiry dates.
    Saddens me how much faith and dependency people place in Google. I've seen many stores go out of business because they let themselves become dependent on Google.

    If you *really* want to know why the site is (apparently) slow, try this site:
    http://www.webpagetest.org/

    When the results come in click on the 'details' view. It should then be *obvious* what is causing the slowdowns. There are many similar site to this one and I'm recommending this for no particular reason other than it is in my bookmarks :)

    One thing that will probably stand out as being a problem is the "Effective use of CDN" will have an "X" rather than a tick. If you are *serious* about improving performance (and reducing bandwidth as a 'side effect') it is to use a CDN (Content delivery network). This one thing can easily double the speed of a site - especially if the slowdowns are caused by lots of static content (such as images).

    Just my 2cents worth.

    RodG

  4. #4
    Join Date
    Feb 2008
    Posts
    529
    Plugin Contributions
    0

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by RodG View Post
    If you need to muss with .htaccess to gain speed you probably have more serious issues at play.
    As a perennial noob I rely on others for guidance, particularly the forum, tutorials.

    If you *really* want to know why the site is (apparently) slow, try this site:
    http://www.webpagetest.org/
    Thanks for link. Results on two tests were - even worse on my ipad, and about same from desktop.

    The worst culprit on time sucking is 'time to first byte loaded'. Google and Webpagetest both say about 5 seconds for desktop. It was 15 seconds on ipad.

    I have a hard time to know if the slow first byte is my server issue or my site host issue. I think its the latter as the test showed the site connect in less than a second. And 15 seconds to the server connect but I am not savy enough to know if that could mean it took my server 15 seconds to make the connect or if it took my host 15 seconds to answer and respond with first byte. (I'm on rural highspeed - slow by most I'm sure - about 5-6 mb download, 1mg upload)

    My image files all show up as cached, but my js, css, and other template files do not. Part of the .htaccess thing was to leverage those as well but requires deflate mod enabled on host apache. I enquired about this on host support ticket, which they didn't answer and closed.

    One thing that will probably stand out as being a problem is the "Effective use of CDN" will have an "X" rather than a tick. If you are *serious* about improving performance (and reducing bandwidth as a 'side effect') it is to use a CDN (Content delivery network). This one thing can easily double the speed of a site - especially if the slowdowns are caused by lots of static content (such as images).
    Oh my. I've had this message on tests before. I thought it meant I should be using a Canadian server! (me being in Canada but using a US server). Oy.

    Just my 2cents worth.
    RodG
    Worth much more than 2 cents. In Canada we no longer have pennies, so it would be rounded to a nickel ;o)

  5. #5
    Join Date
    Jun 2009
    Location
    Sparta, TN
    Posts
    158
    Plugin Contributions
    0

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by RodG View Post
    If you *really* want to know why the site is (apparently) slow, try this site:
    http://www.webpagetest.org/
    When the results come in click on the 'details' view. It should then be *obvious* what is causing the slowdowns. There are many similar site to this one and I'm recommending this for no particular reason other than it is in my bookmarks :)
    RodG
    I like this one too https://gtmetrix.com especially for image optimization because it will optimize your thumbnail images for you to download from the results page. You'll want to make sure you have your large size images already in place - see: https://www.zen-cart.com/content.php...aration-how-to. Another big help for me was this photoshop tutorial.

    Results page does ask you to "Specify a cache validator" - if I'm understanding the way Zen-cart is rotating images for a fresh look upon viewing home page, this isn't possible.
    I'm still trying to determine the best way to handle results: "Optimize the order of styles and scripts" and "Leverage browser caching"
    Good luck!
    My store - closed 12/05/2023
    1.5.7d (upgraded from 1.5.7b), clone a template (cloned Responsive Classic Template), Sitemap XML v4.0, Square WebPay, PayPal Express Checkout, PHP Version: 7.4.29 (Zend: 3.4.0)

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by soxophoneplayer View Post
    I added this code, from zc tutorial to my includes/.htaccess to try and improve my loading speed.

    Code:
    ## Optional caching improvements
    ## Requires mod_header and mod_deflate to be enabled within Apache
    ##################
    <IfModule mod_headers.c>
      Header unset Pragma
      FileETag None
      Header unset ETag
      <FilesMatch ".*\.(ico|jpe?g|JPE?G|gif|GIF|webp|png|swf|flv)$">
        Header set Cache-control "max-age=864000, public, must-revalidate"
        Header unset Last-Modified
      </FilesMatch>
      <FilesMatch ".*\.(html|htm|xml|txt|xsl)$">
        Header set Cache-control "max-age=7200, must-revalidate"
      </FilesMatch>
    </IfModule>
    <IfModule mod_deflate.c>
      <FilesMatch "\.(js|css)$">
        SetOutputFilter DEFLATE
      </FilesMatch>
    </IfModule>
    
    ##################
    ## Optional improvements
    ## Requires mod_expires to be enabled within Apache
    ##################
    <ifmodule mod_expires.c>
      ExpiresActive On
      ExpiresDefault A300
      ExpiresByType application/x-javascript A3600
      ExpiresByType text/css A3600
      ExpiresByType image/gif A604800
      ExpiresByType video/x-flv A604800
      ExpiresByType application/pdf A604800
      ExpiresByType text/html A300
      ExpiresByType image/x-icon A86400
      ExpiresByType image/jpeg A2592000 
      ExpiresByType image/png A2592000 
    </ifmodule>
    You said you're using v1.5.5, and that you applied changes to /includes/.htaccess
    It's important to note that v1.5.5 ALREADY has these changes (and actually some improvements upon them) in /includes/.htaccess. So no changes were necessary to that file.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Feb 2008
    Posts
    529
    Plugin Contributions
    0

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by DrByte View Post
    You said you're using v1.5.5, and that you applied changes to /includes/.htaccess
    It's important to note that v1.5.5 ALREADY has these changes (and actually some improvements upon them) in /includes/.htaccess. So no changes were necessary to that file.
    Oh for cripes sake, I must have thought I already merged it when I saved and uploaded. Another seniors moment.

  8. #8
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: .htaccess cache for improved site speed?

    Quote Originally Posted by soxophoneplayer View Post
    Thanks for link. Results on two tests were - even worse on my ipad, and about same from desktop.)
    This really doesn't make any sense. The testing site performs the tests on/from its own servers and has no bearing on why device you are using.

    Quote Originally Posted by soxophoneplayer View Post
    The worst culprit on time sucking is 'time to first byte loaded'. Google and Webpagetest both say about 5 seconds for desktop. It was 15 seconds on ipad.

    I have a hard time to know if the slow first byte is my server issue or my site host issue.
    Your server and your host are one and the same.

    Quote Originally Posted by soxophoneplayer View Post
    I think its the latter as the test showed the site connect in less than a second. And 15 seconds to the server connect
    Clearly we have a terminology issue here.


    Quote Originally Posted by soxophoneplayer View Post
    but I am not savy enough to know if that could mean it took my server 15 seconds to make the connect or if it took my host 15 seconds to answer and respond with first byte. (I'm on rural highspeed - slow by most I'm sure - about 5-6 mb download, 1mg upload)
    The websire page site test measures performance as *it* sees the site. It really wouldn't matter if you were using 2400bps dialup connection, offhand I think the sitetest uses a 100mbps link.

    Quote Originally Posted by soxophoneplayer View Post
    My image files all show up as cached
    Compression is as important as caching... perhaps moreso (depends on the image sizes)

    Quote Originally Posted by soxophoneplayer View Post
    , but my js, css,
    These are typically so small that they are insiginificant. Personally I find it better to not have these cached, especially while a site is under development.

    Quote Originally Posted by soxophoneplayer View Post
    and other template files do not.
    Almost all the template files are PHP. These will *never* be cached. They are 'dynamic' (output changes depending on the input). Only 'static' (non changing) data/pages can be cached.

    Quote Originally Posted by soxophoneplayer View Post
    Part of the .htaccess thing was to leverage those as well but requires deflate mod enabled on host apache. I enquired about this on host support ticket, which they didn't answer and closed.
    I haven't seen an apache server where mod_deflate hasn't been included by default for many years.

    Quote Originally Posted by soxophoneplayer View Post
    Oh my. I've had this message on tests before. I thought it meant I should be using a Canadian server! (me being in Canada but using a US server). Oy.
    LOL. Yeah, I can see where you got that idea from.

    Cheers
    RodG

  9. #9
    Join Date
    Aug 2014
    Location
    Lisbon
    Posts
    594
    Plugin Contributions
    0

    Default Re: .htaccess cache for improved site speed?

    I was doing the same mistake with zc155. So I clear the root .htaccess , just had the CEON stuff there.

    But without adding to the root .htaccess file the bmz_cache folder images are not cached.
    So I add this to the root .htaccess , but I'm not sure if it's ok to do it

    ##################
    ## Optional caching improvements
    ## Requires mod_headers to be enabled within Apache
    ##################
    <IfModule mod_headers.c>
    Header unset Pragma
    FileETag None
    Header unset ETag
    <FilesMatch ".*\.(jpe?g|gif|webp|png|swf)$">
    Header set Cache-control "max-age=864000, public, must-revalidate"
    Header unset Last-Modified
    </FilesMatch>
    </IfModule>


    However , I still don't understand why the js and css files are not being cache.
    tested this on webpagetest.org

    Code:
    Leverage browser caching of static assets: 88/100
    FAILED - (5.0 minutes) - http://example.net/includes/templates/tpl/jscript/tpl.js
    FAILED - (5.0 minutes) - http://example.net/includes/templates/tpl/fonts/material-iconfont/MaterialIcons-Regular.woff
    FAILED - (5.0 minutes) - http://example.net/includes/templates/tpl/fonts/roboto/roboto-medium-webfont.woff
    FAILED - (5.0 minutes) - http://example.net/includes/templates/tpl/fonts/lora/lora-regular-webfont.woff
    WARNING - (60.0 minutes) - http://example.net/includes/templates/tpl/css/stylesheet.css
    WARNING - (24.0 hours) - http://example.net/includes/templates/tpl/images/icons/favicon.ico

    For the woff fonts, etc , I add this to the includes/.htaccess

    Code:
    # Web fonts
    
        # Embedded OpenType (EOT)
        ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
        ExpiresByType font/eot                              "access plus 1 month"
    
        # OpenType
        ExpiresByType font/opentype                         "access plus 1 month"
    
        # TrueType
        ExpiresByType application/x-font-ttf                "access plus 1 month"
    
        # Web Open Font Format (WOFF) 1.0
        ExpiresByType application/font-woff                 "access plus 1 month"
        ExpiresByType application/x-font-woff               "access plus 1 month"
        ExpiresByType font/woff                             "access plus 1 month"
    
        # Web Open Font Format (WOFF) 2.0
        ExpiresByType application/font-woff2                "access plus 1 month"
    Yet, for js and css

    Code:
    Leverage browser caching of static assets: 96/100
    FAILED - (5.0 minutes) - http://example.net/includes/templates/tpl/jscript/tpl.js
    WARNING - (60.0 minutes) - http://example.net/includes/templates/tpl/css/stylesheet.css

    Don't know what to do .....
    “Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

  10. #10
    Join Date
    Apr 2006
    Location
    West Salem, IL
    Posts
    2,748
    Plugin Contributions
    0

    Default Re: .htaccess cache for improved site speed?

    @soxophoneplayer
    Part of the .htaccess thing was to leverage those as well but requires deflate mod enabled on host apache. I enquired about this on host support ticket, which they didn't answer and closed.
    Note the gzip in the following response header for your site....mod_deflate is enabled already
    Date: Sat, 08 Oct 2016 12:57:53 GMT
    Server: Apache
    X-Powered-By: PHP/5.4.45
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Content-Length: 10534
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: text/html; charset=utf-8
    Mike
    GeekHost - Zen Cart Certified & PCI Compliant Hosting
    The Zen Cart Forum...Better than a monitor covered with post-it notes!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v139h Speed up the Back end Orders speed and DB Size questions
    By explorer1979 in forum General Questions
    Replies: 0
    Last Post: 28 Aug 2012, 02:40 AM
  2. how is this speed and can this be improved?
    By raj3396 in forum General Questions
    Replies: 1
    Last Post: 12 Apr 2012, 11:07 AM
  3. How to Speed Up My Site?
    By blackhalo in forum Basic Configuration
    Replies: 17
    Last Post: 24 Sep 2010, 07:20 PM
  4. How to speed my site?
    By Mikado in forum General Questions
    Replies: 6
    Last Post: 16 Dec 2007, 12:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR