[英]Load assets in Rails 3.2 with Modernizr.load
I want to be able to load in certain JS files using Modernizr.load -- 我希望能够使用Modernizr.load加载某些JS文件 -
Modernizr.load({
test : Modernizr.touch,
yep : '/assets/mobile.js',
nope : '/assets/desktop.js',
});
but when this get compiled for production, those paths do not exist anymore. 但是当它被编译为生产时,这些路径不再存在。 How can I sort out loading in this way?
如何以这种方式整理装载?
You will need to add those assets to config.assets.precompile
in your environment config file (found in config/environments/production.rb). 您需要将这些资产添加到环境配置文件中的
config.assets.precompile
(在config / environments / production.rb中找到)。 Here's an example: 这是一个例子:
config.assets.precompile += %w(mobile.js desktop.js)
These assets can then be referenced by Modernizr: 然后,Modernizr可以引用这些资产:
Modernizr.load({
test : Modernizr.touch,
yep : '/assets/mobile.js',
nope : '/assets/desktop.js',
});
EDIT: You should also make sure these assets are NOT included in your application.js manifest. 编辑:您还应该确保这些资产不包含在您的application.js清单中。 Including them in application.js would defeat the purpose of conditionally loading them for specific feature-less browsers.
将它们包含在application.js中会破坏为特定功能的浏览器有条件地加载它们的目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.