Results 1 to 6 of 6

Thread: httpd/browser caching of javascript/css files

  1. #1
    rocketraman is offline Member
    Join Date
    Jun 2006
    Posts
    5

    Default httpd/browser caching of javascript/css files

    For every page load, Sugar does about 10-30 http GETs for various css, js, gifs, and so forth. I have configured Apache to tell the browser to cache these files by adding the following to my httpd config (found on another forum post):

    Code:
    AddType text/x-component .htc
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css
    ExpiresByType text/html "access plus 1 day"
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType text/javascript "access plus 7 days"
    ExpiresByType application/x-javascript "access plus 7 days"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 month"
    ExpiresByType text/x-component "access plus 1 day"
    However It seems that Sugar appends the version to the query string for http GETs for css and js files, for example here is an example GET from my access logs:

    x.x.x.x - - [24/Sep/2006:19:54:10 -0400] "GET /sugarsuite/themes/Sugar/style.js?s=4.5.0b&c= HTTP/1.1" 200 1093

    I believe that the inclusion of a query string on these files is preventing apache (and the web browser) from caching these js and css files.

    Any solutions?

    Cheers,
    Raman

  2. #2
    stevec is offline Sugar Community Member
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,100

    Default Re: httpd/browser caching of javascript/css files

    Hi,

    Using the firefox livehttpheaders tool, you can use the 'generator' tab to monitor all the requested and downloaded files (make sure all the options are selected to see exactly what it's doing). http://livehttpheaders.mozdev.org/

    On mine, it's caching css and js fine.

    If you're using apache and ssl, make sure you've got it enabled for the ssl sites too.

  3. #3
    rocketraman is offline Member
    Join Date
    Jun 2006
    Posts
    5

    Default Re: httpd/browser caching of javascript/css files

    Quote Originally Posted by stevec
    Hi,

    Using the firefox livehttpheaders tool, you can use the 'generator' tab to monitor all the requested and downloaded files (make sure all the options are selected to see exactly what it's doing). http://livehttpheaders.mozdev.org/

    On mine, it's caching css and js fine.

    If you're using apache and ssl, make sure you've got it enabled for the ssl sites too.
    Nice tool... installed it and confirmed that css and js are not being cached. I am using SSL -- but I have set the options above specifically in the Location directive for my SugarCRM directory and still no dice. Are there any other settings I need to set/check?

    Do you also have a query string appended to your GETs, and is your caching working despite that?

    Cheers,
    Raman

  4. #4
    stevec is offline Sugar Community Member
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,100

    Default Re: httpd/browser caching of javascript/css files

    Hi,

    Yes - the query strings are appended to those GETS but they are being cached, The pertinent part of the config is:

    Code:
    ExpiresActive On
    ExpiresDefault "access plus 300 seconds"
    
            DocumentRoot /var/www/
            RewriteEngine On
            RewriteCond %{REQUEST_METHOD} ^TRACE
            RewriteRule .* - [F]
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/>
                    Options FollowSymLinks MultiViews
                    AllowOverride None
                    Order allow,deny
                    allow from all
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css
        ExpiresByType text/html "access plus 1 day"
        ExpiresByType text/css "access plus 1 day"
        ExpiresByType text/javascript "access plus 7 days"
        ExpiresByType application/x-javascript "access plus 7 days"
        ExpiresByType image/gif "access plus 1 month"
        ExpiresByType image/jpg "access plus 1 month"
        ExpiresByType image/png "access plus 1 month"
        ExpiresByType image/x-icon "access plus 1 month"
    
                    # This directive allows us to have apache2's default start page
                    # in /apache2-default/, but still have / go to the right place
                    # Commented out for Ubuntu
                    #RedirectMatch ^/$ /apache2-default/
            </Directory>
    
            <Directory /var/www/sugarcrm>
                    Options FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
            </Directory>

  5. #5
    rocketraman is offline Member
    Join Date
    Jun 2006
    Posts
    5

    Default Re: httpd/browser caching of javascript/css files

    Interesting... this morning it just started working (i.e. caching the css/javascript files), without me changing a thing.

    The only thing I can think of is that I recently upgraded to 4.5b2 (over the weekend) and the changes and/or date on the files was preventing Apache from sending back the expires header properly (yes, I had restarted Apache after the upgrade). Anyway, whatever the reason, it seems to be working now.

    Thanks a lot for the help.

    Cheers,
    Raman

  6. #6
    WayneSugar's Avatar
    WayneSugar is offline Sugar Community Member
    Join Date
    Oct 2005
    Posts
    155

    Default Re: httpd/browser caching of javascript/css files

    Just FYI, we append the sugar version (and a custom version that is set in your config.php) to prevent the browser caching .js / .css files between upgrades.

    So sugar_3.js?s=4.2.1 will become sugar_3.js?s=4.5.0 after upgrade and this will force the browser to download the .js file since it is a different URL.

    In our testing http(s), Firefox, IE all cache the .js files and .css files with these GET parameters.
    Wayne Pan
    Software Eng.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •