Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:41:31+00:00 2026-05-26T04:41:31+00:00

What is the best way to include CSS external files? from general to specific

  • 0

What is the best way to include CSS external files? from general to specific or the opposite?

More precisely in Rails 3.1, the default application.css (no Sass) generated contains:

/*
 *= require_self
 *= require_tree .
 */

It goes from specific to general so I guess if I want to add jQuery UI theme for example, the best would be:

/*
 *= require_self
 *= require_tree .
 *= require jquery-ui/smoothness/jquery-ui-1.8.16.custom.css
 */

instead of:

/*
 *= require jquery-ui/smoothness/jquery-ui-1.8.16.custom.css
 *= require_self
 *= require_tree .
 */

I ask this question because I know that for example in C++ it is recommended to go from the most specific to the most general.

The same question stands for .js includes, by default Rails generates (no CoffeeScript):

//= require jquery
//= require jquery_ujs
//= require_tree .

Here it seems to go the opposite: from general to specific.

Did the Rails devs choose a default sorting on purpose, or is it just random? If there is no preferable way from a technical point of vue, what are the conventions usually used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:41:32+00:00Added an answer on May 26, 2026 at 4:41 am

    CSS has to be included with general rules first and then more specific rules. This allows the more specific rules to always override the general rules (in the cases where you want that to happen) without explicitly having to manage CSS specificity.

    So, if you had these two CSS rules:

    // general rule
    .subitem {color: blue;}
    
    // more specific rule
    .currentitem {color: red;}
    

    And, you had HTML like this:

    <ul>
        <li class="subitem">Item</li>
        <li class="subitem currentitem">Item</li>
        <li class="subitem">Item</li>
        <li class="subitem">Item</li>
    </ul>
    

    You would want to make sure that the more specific rule for .currentItem came after the more general rule for .subitem so that the .currentitem rule would be in effect when you wanted it to be.

    Javascript files must be included in an appropriate dependency order. For example, if you have javascript file B that uses functions in file A in it’s initialization code, then file A must be included before file B. If two javascript files have no initialization dependencies (e.g. they don’t call functions in each other at initialization), then they can be in any order.

    FYI, in javascript files, you should make sure that no functions in the global namespace or in a specific namespace exist with the same name in multiple files. If so, the last one to be included will be the one that is in effect. In general, you should not rely on this behavior, but should remove conflicting functions with the same name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please recommend the best and easiest way to include multiple Javascript files
What is the best way to include an html entity in XSLT? <xsl:template match=/a/node>
What is the best way to include data in an HTML page? The data
What is the best way to accomplish the following in C? #include <stdio.h> struct
I'm trying to decide the best way to include an image that is required
It's a conceptual question. What's the best way to inlude assets like CSS, Javascript
I am thinking about the best way of including a JS library into rails
the best way to explain is with example so: this is the model public
The best way I can think of to ask this is by example... In
The best way of describing this is I have a table of people with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.