The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Enabling browser caching

Discussion in 'Workarounds and Optimization' started by meldroz, May 31, 2012.

  1. meldroz

    meldroz Registered

    Joined:
    May 31, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm new to Cpanel and server administration in general. I need to enable client caching because of i have a lot of static images that i will probably never change. I looked online and there seem to be different way of doing this.
    I'm running cpanel and easyapache install.

    Thank you,

    Mel
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,478
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Unless a user specifically has caching in their browser disabled, they should be already.
     
  3. Chris.Bshm

    Chris.Bshm Member

    Joined:
    Oct 20, 2011
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    It seems you may be wanting to discuss server side caching for Apache. These options would include eAccelerator, XCache, etc. There are a few downsides with installing these, ex:

    eAccelerator:
    Generates cached files in /tmp - depending on the size of your /tmp directory this can become full causing services like MySQL to fail.
    Additional CPU Usage to generate cache pages.

    Also, eAccelerator is not compatible with PHP Handlers like SuPHP which is installed by default. This however can be changed in WHM >> Configure PHP & SuEXEC; additionally, eAccelerator can be installed via WHM >> EasyApache >> Exhaustive Options List

    https://eaccelerator.net/
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    No PHP OPCode caching options (eAccelerator, xCache, APC) work with suPHP, so it isn't just eAccelerator that doesn't function with it. DSO and FCGI do work with OPCode caching, but I don't understand the purpose of having OPCode caching for PHP if the main reason is to cache images? It only works for PHP and hasn't anything to do with image files (jpg, png, gif, etc.).
     
  5. srpurdy

    srpurdy Well-Known Member

    Joined:
    Jun 1, 2011
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    I think what you really want is a CDN of some sort. That will take load off your server, and serve static content for you from a global network. Browsers are configured by default to cache content. As long as you use good expire headers on files you should be okay. (you may want to compile in mod_headers and mod_expire into apache if you do want control over this.

    you may also make sure compression is enabled for browsers that support compression so that the size of the site data is much smaller with gzip compression. I don't remember if this on by default or not in cpanel.. (you can install mod_deflate) for this.

    I usually use rules like this in htaccess, although you can customize them for how you want.
    Code:
    # 1 YEAR
    ExpiresActive On
    <FilesMatch "\.(otf|ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    ExpiresDefault "access plus 1 years"
    Header unset Last-Modified
    Header unset ETag
    SetOutputFilter DEFLATE
    </FilesMatch>
    
    # 1 MONTHS
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2419200, public"
    ExpiresDefault "access plus 1 month"
    SetOutputFilter DEFLATE
    </FilesMatch>
    
    <FilesMatch "\.(xml|txt|css|js)$">
    Header set Cache-Control "max-age=604800, public"
    ExpiresDefault "access plus 1 week"
    SetOutputFilter DEFLATE
    </FilesMatch>
    
    # 30 MIN
    <FilesMatch "\.(html|htm|php)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    
     
    #5 srpurdy, Jul 14, 2012
    Last edited: Jul 14, 2012
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    mod_deflate isn't installed by default. Also, it isn't added after installing in EasyApache onto sites by default. You'd have to either add an .htaccess such as you are mentioning after adding mod_deflate or use cPanel > Website Optimization to add content to the /home/username/.htaccess we add for it.

    Please note that when adding Website Optimization in cPanel, we place the mod_deflate compression lines into /home/username/.htaccess rather than /home/username/public_html/.htaccess. We do this because subdomains and addon domains aren't always placed into public_html since you can have them at /home/username/subdomainfolder and for mod_deflate to handle all sites under that scenario, the .htaccess has to be in the document root.
     
Loading...
Similar Threads - Enabling browser caching
  1. bou3lam
    Replies:
    8
    Views:
    757

Share This Page