2014-10-17 37 views
0

我正在學習Ruby on Rails和JavaScript。無論如何只有在railsapp需要時才加載js文件?我試圖創建簡單的應用程序,但是當我檢查日誌時,我意識到它總是加載所有的js,即使是不需要的庫。只在需要時加載JavaScript和CSS RAILS

我已經搜索過它,發現它使用配置爲特定的頁面加載特定的js。這很好,但是我想當我們處理一個被許多頁面使用的庫時,會很難保持。任何人都可以給出一個好建議

謝謝

回答

1

看看requireJShttp://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.