18

When I want to include any new CSS file or any new JS file, I put it in the header as this

css file

<link rel="stylesheet" href="<?php echo URL; ?>public/css/header.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/index.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/footer.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/signup.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/contactUs.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/option.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/question.css"  />
    <link rel="stylesheet" href="<?php echo URL; ?>public/css/profile.css"  />

js file

<script src=<?php echo URL . "public/Js/profile.js" ?>></script>
    <script src=<?php echo URL . "public/Js/cell.js" ?>></script>
    <script src=<?php echo URL . "public/Js/place.js" ?>></script>
    <script src=<?php echo URL . "public/Js/ontology.js" ?>></script>
    <script src=<?php echo URL . "public/Js/informativeObject.js" ?>></script>
    <script src=<?php echo URL . "public/Js/question.js" ?>></script>

I want something like

<header> 
include all css
include all js
</header>
10
  • How/where would you define "all css"? At what stage do you want this to be expanded (given that the browser can't do that)? Commented May 9, 2012 at 16:33
  • in a folder called public/css and all js in this folder public/js Commented May 9, 2012 at 16:34
  • i am using MVC with .htaccess Commented May 9, 2012 at 16:34
  • i want to work on google chrome and if the answer doesn't work with IE i don't care , i don't want my website to work with IE :) :) Commented May 9, 2012 at 16:35
  • use some tool like minify for PHP, webutilities for Java or Resources for Grails... Commented May 9, 2012 at 16:38

3 Answers 3

2

Minify is a PHP library that will combine all your CSS / JS files into one. Does that help at all?

Sign up to request clarification or add additional context in comments.

1 Comment

it is forbidden on my country :(
2

For CSS, you could use @import:

HTML with CSS:

<style type="text/css">
@import url('index.css');
@import url('footer.css');
</style>

Standalone CSS:

@import url('index.css');
@import url('footer.css');

Browsers include JavaScript as a #include AFAIK so there's no better way than including them all through <script> tags or by using Wintermute's example of a JS minifier.

Edit: JSMin by Crockford is a CLI utility that you can use if you want to work with it offline.

5 Comments

i use that code in a css file or php file ?
@WilliamKinaan, the code example is for HTML which can be generated within a PHP file. You could also strip the <style> tags from it such that it would be pure CSS. In short, you could use it in both.
i understood from you this 1- in my html header i will put this <link href="mycssfile.css"/> 2-in mycssfile.css i will put ur code right?
I marked two code examples. In your HTML header, you have two options: 1) place the HTML with CSS directly into your HTML header or 2) put the Standalone CSS into mycssfile.css and include that into your HTML header as <link href="mycssfile.css" />. Either option depends on your preference.
yes man it works but i had to put this rel="stylesheet"
1

Assuming you've got an array of files (using the local filesystem path)

print "<style type='text/css'>\n";
showall($css);
print "</style>";


function showall($filelist)
{
   foreach ($filelist as $fname) {
      print file_get_contents($fname) . "\n";
   }
}

1 Comment

this code where should i use it ? and how can i call it from my html ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.