Hi guys,
I have been trying numerous methods to get expires headers to work with
apache and rails. I’m on a debian ubuntu server with:
sudo a2enmod rewrite expires headers deflate
… all on …
I’m using something similar in my Virtual site under the directory
block:
gzip html, css and js
AddOutputFilterByType DEFLATE text/html text/css
application/x-javascript application/javascript
far future expires headers
ExpiresActive On
<FilesMatch “.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)?d{10}$”>
ExpiresDefault “access plus 10 years”
I’m not using 10 years though, this is just an example script. I also
tried:
add something we can do a directory match on
RewriteCond %{QUERY_STRING} ^[0-9]{10}$
RewriteRule ^(.*)$ /add_expires_header%{REQUEST_URI} [QSA]
the add_expires_header directory is just a symlink to public
<Directory “/path/to/rails_app/public/add_expires_header”>
ExpiresActive On
ExpiresDefault “access plus 10 years”
and added the symlink for :
cd /path/to/rails_app/public
ln -s . add_expires_header
The problems I face are the following:
I want to use expire headers with all of the following content:
ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf
I also want the expire headers to work with images being loaded from CSS
files. Rails puts the datetime stamp on all of my content so it should
work with the ?datetimestamps too.
I’m sure someone here has setup something that works well. I could use
some help to get this working. In my case, sometimes the rails
?timestamps are ignored and YSlow shows the content not being expired…
Thanks.
I decided to wait 24 hours before rebumping my thread. I still could
use some assistance with this. I’m not sure how many out there use
expire headers but I would like to accomplish this task with rails.
Please look over my former response and if you have expires headers
working with your site, I could use some pointers for mine.
Many thanks.
On Aug 14, 5:33 pm, Alpha B. [email protected]
wrote:
block:
gzip html, css and js
AddOutputFilterByType DEFLATE text/html text/css
application/x-javascript application/javascript
far future expires headers
ExpiresActive On
<FilesMatch “.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)?d{10}$”>
Don’t think that will actually match your files because…
- the d is missing a \
- the ? will be interpreter as a quantifier not a literal ?
Also you probably want the . to be literal dot, but that won’t prevent
it matching
You could check all this be looking at what expires headers are
actually being generated.
Fred
On Aug 15, 8:54 pm, Alpha B. [email protected]
wrote:
my-image.gif?(timestamp) - those are not being expired.
In addition, any image content served from my css files:
background-image: url(/images/background_defense.jpg);
Well those don’t have a timestamp on them so don’t match your
filesmatch clause. Have you tried fiddling with the regular expression
(or using ExpiresByType) ?
Fred
Hi Fred,
So far, the only things being expired are the following:
All .css
All .js
All images served by rails that don’t contain _ underscores or -
hyphens.
If an image served by rails is for instance my_image.gif?(timestamp) or
my-image.gif?(timestamp) - those are not being expired.
In addition, any image content served from my css files:
background-image: url(/images/background_defense.jpg);
is also not being expired.
==============
I changed the piece you mentioned to:
far future expires headers
ExpiresActive On
<FilesMatch “.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)?d{10}$”>
ExpiresDefault “access plus 10 years”
… the same thing still occurs.
Any ideas? Many thanks mate.
Fred, good call mate.
ExpiresDefault worked great for css, js, and swf
ExpiresBytype worked great for all images, including those within css
I pushed the expires to access plus 4 months since that’s the football
season length and if any site modifications occur, they’ll happen after
that time.
My site now grades out as an A in Expire Headers with YSlow.
Overall, my entire site grades out as a B with YSlow, almost at an A.
It’s pretty speedy too.
Take care,
Alpha B. wrote:
[…]
My site now grades out as an A in Expire Headers with YSlow.
Overall, my entire site grades out as a B with YSlow, almost at an A.
It’s pretty speedy too.
Don’t put too much faith in YSlow. Remember that it was designed to be
an internal tool at Yahoo!. That means that it’s great if you’re Yahoo!
or if you have similar usage patterns, but if you don’t, it can be very
misleading. For example, on my projects, I’ve found most components of
it nearly useless.
Take care,
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]