This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » Test assets are cached in production...
expandshrink

Test assets are cached in production environment

Test assets are cached in production environment

Friday 20 June 2014 3:11:45 pm - 3 replies

Hi,

I'm moving a site to production and testing cache. Unfortunately I don't have a reverse proxy, so I'm using the internal Symfony HttpCache.

How can I test my assets are correctly cached? From the header response of my css for example, I see there's an Etag. Does it mean it has been cached? (The response I receive is 200 and not 304).

By the way, how can I show the Symfony profiler bar on production?

Thanks!

Modified on Friday 20 June 2014 3:12:45 pm by John Terra

Friday 20 June 2014 4:27:01 pm

etag does not mean that an asset is cached. It is a response header which goes out along with response payload, basically on all requests for the asset.

If you have an etag in the 1st response, and reload the page / resend the request for the asset, you should see a 304. If you do not, etag is not working.

But you might be confusing things a bit here - the Symfony http cache has little to do with assets.

What has to do with asssets is the rewrite rules in vhost/htaccess. For prod, you uncomment the 2 rewrite rules which allow requests for assets to hit the disk instead of the sf controller, and run the assetic dump command.

This way each request for static assets will not be wasting an sf process.

Modified on Friday 20 June 2014 4:27:35 pm by Gaetano Giunta

Saturday 21 June 2014 2:50:28 pm

Thanks Gaetano.

Right now I receive 200 for html and css, and 304 for image.

Which are the 2 lines in the vhost that you mention? Here's my rules in production:

 

SetEnv APP_ENV prod

 SetEnv ENVIRONMENT prod

 SetEnv APP_DEBUG false

 SetEnv USE_DEBUGGING false

 

RewriteEngine On 

RewriteRule ^/api/[^/]+/v1/ /index_rest.php [L] 

RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* - [L] 

RewriteRule ^/var/([^/]+/)?cache/(texttoimage|public)/.* - [L] 

RewriteRule ^/design/[^/]+/(stylesheets|images|javascript|fonts)/.* - [L] 

RewriteRule ^/share/icons/.* - [L] 

RewriteRule ^/extension/[^/]+/design/[^/]+/(stylesheets|flash|images|lib|javascripts?)/.* - [L] 

RewriteRule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L] 

RewriteRule ^/packages/styles/.+/thumbnail/.* - [L] 

RewriteRule ^/var/storage/packages/.* - [L] 

RewriteRule ^/favicon\.ico - [L] 

RewriteRule ^/design/standard/images/favicon\.ico - [L] 

RewriteRule ^/robots\.txt - [L] 

RewriteRule ^/w3c/p3p\.xml - [L] 

RewriteRule ^/bundles/ - [L] 

RewriteRule ^/css/.*\.css - [L] 

RewriteRule ^/js/.*\.js - [L] 

RewriteRule ^/images/.* - [L] 

RewriteRule .* /index.php 

 

Thanks

Modified on Saturday 21 June 2014 2:52:00 pm by John Terra

Monday 23 June 2014 10:59:20 am

The two rewrite lines are the /js and /css ones, which you seem to have active - meaning those resources will be read from disk.

If you get a 304 for images but not for css/js, it is probably part of the Apache configuration, in the vhost or somewhere else.

You can google around for how to set up properly etag for directories or file types.

Also, for even better performances, you can set up some expiration date for all of them (images + css + js), using something like

 

    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType application/javascript "access plus 1 hour"
        ExpiresByType text/css "access plus 1 hour"
    </IfModule>

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from