General Question

AlexChoi's avatar

Stylesheet_link_tag, javascript_include_tag, caching problems?

Asked by AlexChoi (305points) June 2nd, 2008

So, the new caching for stylesheet_link_tag, javascript_include_tag
which rolls up the files into one all.js or all.css files is great…
however I’ve run into an issue:

If all.cs or all.js don’t exist, they get generated… great, I’ve
reduced the number of gets…

The problem is what occurs when the files already exist… even if
I’ve changed my list of js/css files to something completely
different, it won’t rewrite the file if it already exists…

Do we really need the unless in this block? (asset_tag_helper.rb)

def write_asset_file_contents(joined_asset_path, asset_paths)
  unless file_exist?(joined_asset_path)
    FileUtils.mkdir_p(File.dirname(joined_asset_path))
    File.open(joined_asset_path, “w+”) { |cache|
cache.write(join_asset_file_contents(asset_paths)) }
  end
end

Observing members: 0 Composing members: 0

1 Answer

xyzzy's avatar

First, I should say that I am not familiar with Rails, so take this as generic advice:

Without that unless, the file would get recreated every time. This would be a very bad idea, as you could have one get rewriting the file at the same time another get is trying to read it (I’m assuming that this function is called on every request).

What you need is additional logic to detect if it needs to be regenerated due to changes in other files. A simple but inefficient way is to compare timestamps of your source files with the all.cs and all.js files.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther