| Author |
Message |
drath D

Joined: 27 Sep 2005 Posts: 1696 Location: Canada
|
Posted: Sun May 11, 2008 10:39 am Post subject: CSS Without Linking |
|
|
I couldn't find much information on this: Why would you link to a CSS file rather than just having the style sheet inline with the html document? Well I'm guessing it's so it keeps the information cached when you go to different pages on the website, so it doesn't have to keep loading the data, making it more efficient/speedy.
But what about if your website only has one page. Is it then alright to just use inline CSS? Isn't it less efficient to link a to a CSS (using <link rel=>) if there is only one page? _________________ The Gamer's Journal | Online Portfolio | Half-Life Library | UNDATA |
|
| Back to top |
|
| |
ClickFanatic Est. 2005

Joined: 18 Jan 2005 Posts: 3926 Location: A particular geographic area
|
Posted: Mon May 12, 2008 4:17 am Post subject: |
|
|
The whole point to have external CSS files is to save bandwidth, because the CSS file is cached seperately. Inline CSS is attached to the document and will therefore be transferred every time the document is loaded.
If your site only has one page, then you can just embed the CSS in it, because HTML documents are cached as well.
Having CSS externally would require another HTTP request to the server, which is arguably less efficient in such a situation. _________________ Captain Jell-O Buster from the Future
[img]http://feeds.feedburner.com/sparepencil.1.gif[/img] |
|
| Back to top |
|
| |
exsanguination Forum Regular
Joined: 27 Apr 2005 Posts: 418 Location: Australia
|
Posted: Wed May 14, 2008 6:12 pm Post subject: Re: CSS Without Linking |
|
|
I'd look at it more from the other direction, why would you inline it when you can link to an external stylesheet? What benefits does it gain you? I'd say basically nothing but maintenance headaches.
I like to keep everything separate. HTML is separate from JavaScript, which is separate from CSS, which is separate from server code.
Its just good practice.
And what CF said about caching. |
|
| Back to top |
|
| |
Rashy Lifeless Person
Joined: 25 Sep 2006 Posts: 661
|
Posted: Thu May 15, 2008 4:54 pm Post subject: |
|
|
For multi-page sites, having the CSS inline would be a nightmare. If you wanted to update something like the font color for your content, with inline CSS you would have to edit the CSS on every single page, whereas if it was separate you would just change the one CSS file. _________________ Rashy! |
|
| Back to top |
|
| |
spock iSpock

Joined: 23 Mar 2005 Posts: 2899 Location: The Netherlands
|
Posted: Sat May 17, 2008 10:19 am Post subject: |
|
|
| Rashy wrote: | | For multi-page sites, having the CSS inline would be a nightmare. If you wanted to update something like the font color for your content, with inline CSS you would have to edit the CSS on every single page, whereas if it was separate you would just change the one CSS file. |
Although that really isn't a big issue if you're using a cms or using php's include() for example.
ClickFanatic is completely right. Although it won't make much difference on really small sites it will when you're serving a bigger website. (Edit: I mean big and small expressed in the number of visitors/pageviews) _________________ My new site
My OpenTTD data package |
|
| Back to top |
|
| |
Luth Novice Poster
Joined: 22 May 2008 Posts: 17
|
Posted: Fri May 23, 2008 2:14 pm Post subject: |
|
|
| spock wrote: | Although that really isn't a big issue if you're using a cms or using php's include() for example.
ClickFanatic is completely right. Although it won't make much difference on really small sites it will when you're serving a bigger website. (Edit: I mean big and small expressed in the number of visitors/pageviews) |
Your not completely correct here because alot of the time smaller sites are the ones that are constantly trying to save bandwith do to file hosting or images or various other reasons and most free hosts dont offer enough bandwith. So making an extrenal style sheet would be a wiser way to go.
Also it is good practice to keep your code neat and easy to maintian. |
|
| Back to top |
|
| |
spock iSpock

Joined: 23 Mar 2005 Posts: 2899 Location: The Netherlands
|
Posted: Mon May 26, 2008 10:10 am Post subject: |
|
|
| Luth wrote: | | spock wrote: | | Although that really isn't a big issue if you're using a cms or using php's include() for example. |
Your not completely correct here because alot of the time smaller sites are the ones that are constantly trying to save bandwith do to file hosting or images or various other reasons and most free hosts dont offer enough bandwith. |
Ok, true. But usually bandwidth is not the biggest issue, and some small css doesn't really use that much bandwidth compared to images on the site. _________________ My new site
My OpenTTD data package |
|
| Back to top |
|
| |
marinaroz Grey Scaled

Joined: 04 Mar 2004 Posts: 2813 Location: Israel
|
Posted: Fri May 30, 2008 8:00 am Post subject: |
|
|
There's an important difference between having your CSS in the same file as your HTML, and between actually using it inline, meaning mixed within your HTML.
Using CSS inline shouldn't be done in most cases, it makes your code awkward and inflexible. Difficult to make styling changes.
There's nothing I can think of against having the CSS put in the same file as the HTML, nicely separated, if it's a one page site though. Not that you actually gain something by doing that in a tiny site, either. _________________ Tarakana NET |
|
| Back to top |
|
| |
drath D

Joined: 27 Sep 2005 Posts: 1696 Location: Canada
|
|
| Back to top |
|
| |
Necromis Lifeless on my Boat

Joined: 11 Apr 2005 Posts: 748 Location: USA
|
Posted: Tue Jun 03, 2008 9:50 am Post subject: |
|
|
| to be honest, as was said before, the best practice is to keep them seperate and link your html and css. Yes PHP includes could work, but that is defeating the purpose of the linking abilities of CSS. Additionally you may only have one page now, but what about when down the road it grows and you need more pages. You can simply link to that same CSS sheet. Clean HTML and CSS is so much nicer to work with, and makes editing either a breeze. Start combining all that code together and you have to hunt hunt hunt for simple changes. |
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7108 Location: The cheese is made out of moon
|
Posted: Tue Jun 03, 2008 11:22 am Post subject: |
|
|
| Luth wrote: |
Your not completely correct here because alot of the time smaller sites are the ones that are constantly trying to save bandwith do to file hosting or images or various other reasons and most free hosts dont offer enough bandwith. So making an extrenal style sheet would be a wiser way to go.
Also it is good practice to keep your code neat and easy to maintian. |
It's not as important for smaller sites as it is for big sites. A few kilobyte per visitor more or less is nothing for smaller websites. But if you have a website with over 1000 unique visitors a day with pages that aren't cached cause they're dynamic you'll probably want to move your style sheet to a separate file cause that would save quite some bandwidth at the end of the month. _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
|
|
|