The solution to Web apps + AJAX = distribution problem?

A better solution to fix the caching problem:

I added some lightweight code in my template to check the modified time of all css/script files, and link to them in the form "filename?mtime". The extra argument is ignored by the web server, so you don't have to rename the files, and since its based on the modification time the link only changes when the file does.

Thanks to Abe, whom I met while visiting JotSpot to talk about Dojo.

In rails, you can create/modify the stylesheet_link_tag, javascript_link_tag commands to use the File.stat command and append the ?#### to the link url.

  def my_javascript_tag( script )
    script_ver = File.stat( RAILS_ROOT + "public/javascripts/#{script}.js" ).mtime.to_i
    "<script src=\"/javascripts/#{script}.js?#{script_ver}\" type=\"text/javascript\"></script>"
  end

Share/Save/Bookmark

Published

Thu, 08 Sep 2005

View Comments


Want more like this?

Subscribe via RSS
or by email:

New Relic