what is the best way to add for example a css-file to a webpage or are there any differences between link-tag and require/include? The reason why I'm asking: My idea is to identify my root folder and use absolute paths so I'm independent of the cwd. (The link to every file would be therefore uniform.) In php there is no problem and it works fine but I can't use it with the link-tag tag or src-tag.
So are there any disadvantages including the external files instead of using html-tags?
Thanks for your help.
First, <link>
tag links CSS assets by the URL path, not the file-system path. Please check if the URL in href
is valid on your browser. This article might give you a good idea on what's going on with the browsers' logics.
Use include or require would pull the text from the CSS into the page and display directly. While <link>
tag tells browser to find the CSS file to download and reference it.
On cold-load (loading the page the first time), there is no speed difference. But your browser would probably cache your CSS file. So if your site has multiple pages with the same CSS, browser would load the second page a bit faster (depends mainly on how large your CSS file is).
I always prefer using <link>
for CSS. Besides, I would not use require or include for CSS on production site.