[英]Rails 3 asset pipeline: How to prevent some asset files from being loaded for everyone (eg. browser-specific)
我想將“ excanvas.min.js”文件僅服務器提供給Internet Explorer,而不是其他瀏覽器 。
所以我在application.html.erb
做了:
<!--[if lt IE 9]>
<%= javascript_include_tag 'excanvas.min'
# Excanvas for use of Canvas in IE up to version 8
%>
<![endif]-->
<%= javascript_include_tag 'application' %>
但我在生產中遇到以下錯誤:
Completed 500 Internal Server Error in 3ms
ActionView::Template::Error (excanvas.min.js isn't precompiled)
強制Rails使用以下命令預編譯文件時,也會發生此錯誤:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)
在“ config / production.rb”中。 我究竟做錯了什么?
我可以做一個
//= require excanvas.min
在application.js
。 但這將包括每個瀏覽器的文件...
信息:我從Rails 3.0應用程序進行了更新。
問題在下面的行中
config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)
%W
是創建數組的快捷方式,項目之間需要用空格分隔。 在您的情況下,您excanvas.min.js,other_file.css,even_anotherfile.js
字符串excanvas.min.js,other_file.css,even_anotherfile.js
到預編譯列表中。
因此,只需按如下所示替換行:
config.assets.precompile += %W(excanvas.min.js other_file.css even_anotherfile.js)
只需為行和添加<%#%>即可。 我認為它們將顯示為評論。
要么
您可以這樣做js。使用js判斷瀏覽器並加載相應的CSS文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.