Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Best way to import multiple css files

  • 29-01-2009 1:10pm
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    We are remaking a large language website. The css is grouped into type,forms,grid,ie6 etc.

    We need to make only 1 http request to the server for the CSS, so, instead of linking each sheet on the page, i was wondering if i could have a dynamic file that imports all the stylesheets ?

    If anyone has any suggestions on the best way to do this please let me know..

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Off the top of my head, I would say a server-side script that combines all the files into one that is included in the pages. So, you upload forms.css, grid.css, ie6.css when you've made changes, and then run a script that concatenates them all into one stylesheet.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Yep, if you've got server side scripting, you could use PHP.

    You have one file called, say "style.css.php", which includes all the other css files, e..g

    [php]
    <?php
    include("css/type.css");
    include("css/forms.css");
    include("css/grid.css");
    include("css/ie6.css");

    ?>[/php]


  • Registered Users, Registered Users 2 Posts: 11,987 ✭✭✭✭zAbbo


    Create a master CSS file, and put the import references there
    /* CSS Master - /css-styles/master.css */
    
    @import url("/css-styles/ie6.css");
    @import url("/css-styles/grid.css");
    @import url("/css-styles/menu.css");
    @import url("/css-styles/form.css");
    
    /* END Import */
    

    And link it as normal in your HTML
    <link rel="stylesheet" href="/css-styles/master.css" type="text/css"  />
    


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    That would still result in multiple HTTP requests though.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Indeed.

    OP, is there any particular reason why you want to reduce the overhead on requests?

    Most servers and browsers create persistent connections when retrieving pages, instead of an individual connection per file. The overhead of having multiple files tends to be negligible - the volume of data is identical.


  • Advertisement
  • Closed Accounts Posts: 35 dkell


    You could take a look at Minify, it can be used for JS & CSS (although I haven't tried it out yet)


  • Registered Users, Registered Users 2 Posts: 2,120 ✭✭✭p


    Unless it's a high performance website, then it's probably not a problem. i'd say the hassle of coming up with a solution, may negate it's benefits for general maintenance and future updates. Unless you're having a problem with a slow website and you really need to optimize, it's probably not neccessary.


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    Bizarre I was only thinking about this yesterday.
    The thing is a given visitor might hit say 5 pages on your site, seperate css files cached at the client works fine but if you create a custom css collation per page you lose the cache win and end up increasing transmission overhead.


Advertisement