Q&A: What is the difference between accessing an external css file in php vs html?

Question by Some G: What is the difference between accessing an external css file in php vs html?
I mean like what are the differences is one a superior less cluttered way to do it or more efficient or something?

being the html way


being the php way

Best answer:

Answer by Scott C
With the PHP approach above, you’re actually inserting the contents of the CSS Stylesheet into your HTML document. With the HTML link approach, you’re simply making the CSS elements accessible to your HTML document.

It’s a matter of individualized view and style, but I like to simply link to the CSS using the HTML link tagset. It’s less cumbersome upon the browser, as it does not add to the page weight, and the page could download and render quicker.

Know better? Leave your own answer in the comments!

Comments

  1. best way is to use :

    @import url(‘”style.css’);

    People generally use PHP include if you need to include particular CSS based on some conditon.

  2. Melissa N says:
  3. oracle128au says:

    There is no difference. Both methods require the same amount of bandwidth (a linked external CSS file still has to be downloaded by the browser). The “PHP way” you mention isn’t actually “the” PHP way, since you could also do
    < ?php echo "“;
    ?>
    and it would look exactly the same as the “HTML way” in the output page source. Your “PHP way” is just using the include() function, which just places the text of the file within the current page.
    It’s better to link an external stylesheet, since it means the page source is less cluttered making it easier to debug. But like I said, you could just as easily do that in PHP or HTML and it makes no difference, other than with PHP you can change the stylesheet on the fly (due to time, date, user preference etc).

Speak Your Mind

*

*

WordPress SEO fine-tune by Meta SEO Pack from Poradnik Webmastera