[英]How to combine multiple css, js files and serve as one file in rails 3?
I have been trying to improve the page load time in Rails 3, I went through few blogs where I learned that I can include the css , js file names in application.css and application.js respectively. 我一直在尝试改善Rails 3中的页面加载时间,我浏览了一些博客 ,了解到我可以分别在application.css和application.js中包含css , js文件名。
For testing purpose I removed the files from the layout and included it in application.css , and then on page reload the css files didn't reload. 为了进行测试,我从布局中删除了文件,并将其包含在application.css中 ,然后在页面重新加载时, css文件没有重新加载。
My current application.css file: 我当前的application.css文件:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require 'owl.carousel.min.css'
*= require 'owl.carousel.min.css'
*= require 'owl.theme.min.css'
*= require "flag-sprites.min.css"
*= require 'owl.transitions.min.css'
*/
layout.html.erb: layout.html.erb:
<%= stylesheet_link_tag "application.css" %>
If you use 如果您使用
*= require_tree .
It will load all the css files inside app/assets/stylesheet so didn't need to mention each file name. 它将加载app / assets / stylesheet中的所有css文件,因此无需提及每个文件名。
One more thing to Note is you need to restart the server after updating the application.css and application.js files. 需要注意的另一件事是,您需要在更新application.css和application.js文件后重新启动服务器。 Hope this help. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.