繁体   English   中英

如何在Rails 3中组合多个CSS,JS文件并用作一个文件?

[英]How to combine multiple css, js files and serve as one file in rails 3?

我一直在尝试改善Rails 3中的页面加载时间,我浏览了一些博客 ,了解到我可以分别在application.cssapplication.js中包含cssjs文件名。

为了进行测试,我从布局中删除了文件,并将其包含在application.css中 ,然后在页面重新加载时, css文件没有重新加载。

我当前的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:

<%= stylesheet_link_tag "application.css" %>

如果您使用

*= require_tree .

它将加载app / assets / stylesheet中的所有css文件,因此无需提及每个文件名。

需要注意的另一件事是,您需要在更新application.css和application.js文件后重新启动服务器。 希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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