开发者

Rails Asset Pipeline: Precompile Assets outside of manifest?

I have certain page-specific js and css files that I either:

  1. Don't want running on development (ie tracking code)
  2. Don开发者_StackOverflow中文版't want running on every page

or both.

In Rails 3.0.x I would simply call them from the view where they are needed like so:

- if some_condition
  = javascript_include_tag 'page_specific'

Now, using the asset pipeline, it looks like I must include these in the manifest (and therefore in every page for the application) or else they won't be precompiled. As I'm using Heroku for deployment allowing lazy compilation is not an option.

How can I manually precompile every file from the assets directory without having to include them all in the manifest? Is this possible?


Just don't put the page specific asset in the manifest and include them when you need it like you did in rails 3.0.x, the precompiler will compile those page specific as separate files.

Personally I just check for a certain element I know is in the dom in that page. If the element isn't found the rest of the code isn't executed.

$(function(){
   if( $("#page_specific_element").length !== 1 ) return;
   //page specific functions
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜