Skip to content

Commit

Permalink
adding an expires header to the stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
madx committed Mar 5, 2009
1 parent b37370c commit 4b87874
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion honk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ def stylesheet(*names)
names.each do |name|
args = {
:rel => "stylesheet", :type => "text/css",
:media => "screen", :href => "/css/#{name}.css"
:media => "screen", :href => versioned_css("/css/#{name}.css")
}
out << partial("%%link{%s}" % args.inspect)
end
out
end

def versioned_css(file)
"%s?%s" % [file, File.mtime(File.join(File.dirname(__FILE__), file)).to_i]
end

def comments_link(post)
comment_string = "#{post.comments.length} comment"
comment_string << 's' if post.comments.length != 1
Expand Down Expand Up @@ -220,6 +224,7 @@ class NoSuchTag < NameError; end
get '/css/:stylesheet.css' do
content_type 'text/css', :encoding => 'utf-8'
stylesheet = params[:stylesheet] + '.css'
response['Expires'] = (Time.now + 60*60*24*365*3).httpdate
File.read(File.join(File.dirname(__FILE__), 'css', stylesheet))
end

Expand Down

0 comments on commit 4b87874

Please sign in to comment.