简体   繁体   中英

load javascript and css only when needed RAILS

I am learning ruby on rails and javascript. Is there anyway to load js file only when needed by the railsapp? I tried to create simple application but when I check on the log, I realize it always load all the js, even the unneeded library.

I already searched it and found that it is using configuration to load a specific js only for specific pages.It's good, but I guess when we deal with a library that is used by many pages,, will make it hard to maintain. Could anyone give a good advice?

thank you

Take a look at requireJS : http://requirejs.org/

RequireJS is a JavaScript file and module loader. 
It is optimized for in-browser use, but it can be
used in other JavaScript environments, like Rhino and Node. Using a 
modular script loader like RequireJS will improve the speed and quality of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM