1

I am using nifty layout from Ryan Bates and that includes Layout helper with following code.

in my application.html.erb

<%= stylesheet_link_tag "application", :cache => true %>
<%= javascript_include_tag :defaults, :cache => true %>
<%= yield(:head) %>

Then in the helper layout_helper.rb

def stylesheet(*args)
  content_for(:head) { stylesheet_link_tag(*args) }
end
def javascript(*args)
  content_for(:head) { javascript_include_tag(*args) }
end

using this in my application i can add css and javascript from any page simply by calling

<% javascript "what_ever" %>
<% stylesheet "what_ever" %>

but the problem i am facing is that these extra css or js files do not get the :cache => true and thus will not be cached.

Is there a way to resolve this?

Basically I want to have small small css files for each page and then serve one big file when it is called.

2 Answers 2

0

Will using

<% javascript "what_ever", :cache => true %>

not work?

Going by the javascript_include_tag doc http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-stylesheet_link_tag it should.

1
  • this does not work as using the layout helper as well as the original call in the application.html.erb, results in two different calls being made. to call two different css files. Commented Jul 27, 2011 at 16:48
0

Did some digging on the net about this.

There are pros and cons for doing the small small files. So the jury is still out.

One site said the small small files help readability so better to use them but then use some programming language to combine all the css files and server them as one.

the benifit of this is that you can still develop the way you prefer but the user only needs to download the file once and does not have to make the calls for each new file.

Taking this approach, the best solution will be to divide each file and match it to the model name. The application.css contains css common to all pages, where as the modelname.css file contains items specific to that model.

then in application.html.erb, you make the call as such.

<%= stylesheet_link_tag :all, :cache => true %>

This will combine all the css files and serve them as one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.