[英]ruby on rails only load 1 css & js file
I am new to ruby on rails
and whenever i create and access
a controller
i can see it loads a new css & js
file with name as the name of the controller... 我是
ruby on rails
新手,每当我创建和access
controller
我都可以看到它加载一个新的css & js
文件,其名称为控制器的名称...
How can i make it load only 1 css and js
file called style.css
and site.js
for example? 我怎么能只加载1个名为
style.css
和site.js
css and js
文件呢?
what is the purpose of having multiple js & css
files whenever i access a contrller? 每当我访问一个控制器时,有多个
js & css
文件的目的是什么?
if i go to application.html.erb
and change 如果我去
application.html.erb
并改变
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
to 至
<%= stylesheet_link_tag("application") %>
<%= javascript_include_tag("application") %>
it doesnt seem to help 它似乎没有帮助
I dont know which Rails version you are using, but assuming it is the recent one, then Rails are using Assets Pipeline, to merge multiple files and serve all css / javascript files compressed / merged. 我不知道你正在使用哪个Rails版本,但假设它是最近的版本,那么Rails正在使用Assets Pipeline,合并多个文件并提供压缩/合并的所有css / javascript文件。
You can learn more about it at http://guides.rubyonrails.org/asset_pipeline.html 您可以在http://guides.rubyonrails.org/asset_pipeline.html上了解有关它的更多信息
Basically what you do is, you reference one file 'application' (css or js) and inside this file, you customize which files it should include. 基本上你所做的是,你引用一个文件'application'(css或js),在这个文件中,你自定义它应该包含哪些文件。
The code: 编码:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
will include all .css
and .js
files available in assets/javascripts/
and assets/stylesheets/
. 将包括
assets/javascripts/
和assets/stylesheets/
提供的所有.css
和.js
文件。 So, if you want to include only the style.css
and site.js
just remove everything else. 因此,如果您只想包含
style.css
和site.js
,请删除其他所有内容。
Your assets/javascripts/
should have only the application.js
and site.js
. 您的
assets/javascripts/
应该只包含application.js
和site.js
And your assets/stylesheets/
should have the application.css
and style.css
. 你的
assets/stylesheets/
应该有application.css
和style.css
。
EDIT 编辑
`application.js
and application.css
are part of the asset pipeline . `application.js
和application.css
是资产管道的一部分。
You can disable it if you want by adding this line in your application.rb
如果需要,可以在
application.rb
添加此行来禁用它
config.assets.enabled = false
You can also change the application.html.erb
to include only your style.css
and site.js
: 您还可以将
application.html.erb
更改为仅包含style.css
和site.js
:
<%= stylesheet_link_tag "style", :media => "all" %>
<%= javascript_include_tag "site" %>
I hope it helps... 我希望它有所帮助......
Try using :cache => 'cache-display'
尝试使用
:cache => 'cache-display'
<%= stylesheet_link_tag :all, :cache => 'cache/display' %>
<%= javascript_include_tag :all, :cache => 'cache/display' %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.