Results 1 to 6 of 6

Thread: Enabling browser caching

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1
    cPanel/WHM Access Level

    Root Administrator

    Default Enabling browser caching

    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. #2
    cPanel Product Evangelist Infopro's Avatar
    Join Date
    May 2003
    Location
    Pennsylvania
    Posts
    10,080
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Enabling browser caching

    Unless a user specifically has caching in their browser disabled, they should be already.

  3. #3
    cPanel Staff
    Join Date
    Oct 2011
    Location
    Houston, TX
    Posts
    13
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Enabling browser caching

    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. #4
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    7,611
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Enabling browser caching

    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.).
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Technical Analyst III, Forums Specialist, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  5. #5
    Member
    Join Date
    Jun 2011
    Posts
    99
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Enabling browser caching

    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>
    Last edited by srpurdy; 07-14-2012 at 06:05 AM.

  6. #6
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    7,611
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Enabling browser caching

    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.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Technical Analyst III, Forums Specialist, cPanel Tech Support

    Submit a ticket | Check an existing ticket

Similar Threads

  1. FCGI + eAccelerator not caching
    By cesarlwh in forum cPanel & WHM Discussions
    Replies: 6
    Last Post: 03-26-2012, 06:15 AM
  2. PHP Caching for Dummies
    By markb14391 in forum cPanel & WHM Discussions
    Replies: 9
    Last Post: 07-24-2010, 06:31 AM
  3. suPHP and caching
    By aegis in forum cPanel & WHM Discussions
    Replies: 14
    Last Post: 09-02-2008, 01:53 PM
  4. Disabling Caching.
    By worldwarme in forum New User Questions
    Replies: 5
    Last Post: 04-01-2007, 07:21 PM
  5. Graphics not caching
    By parhelic in forum cPanel & WHM Discussions
    Replies: 2
    Last Post: 12-06-2003, 05:10 AM