/    Sign up×
Community /Pin to ProfileBookmark

Would it speed up my website if I put all my styles in the header?

In addition to speeding up my site, I can also use PHP variables from my website in the CSS. I know I can dynamically generate CSS files, but I won’t have access to the global variables of my website.

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 04.2010 — Would it speed up my website if I put all my styles in the header?[/QUOTE]Yes: http://stevesouders.com/hpws/rule-css-top.php
Copy linkTweet thisAlerts:
@narutodude000authorSep 04.2010 — What I meant was, would it be faster if I put the styles directly in the header, instead of using an external CSS stylesheet.

I know most people do not recommend this, I will try this later on today see if it's faster. I'll post the results either here or in my blog.
Copy linkTweet thisAlerts:
@handcraftedwebSep 05.2010 — What I meant was, would it be faster if I put the styles directly in the header, instead of using an external CSS stylesheet.....[/QUOTE]

In theory, as 1 file is served instead of 2 in series. But if your page is comprised of 100 files (with all the graphics, etc.), then it will be 99 files served instead of 100. I'll bet the gain is immeasurable. And this is only for a single page.

If multiple HTML pages have the same styles in each of their heads it's probably going to be slower than if the common styles were in a single separate file, which will be loaded once and cached in the browser. I think.

...Mike
Copy linkTweet thisAlerts:
@FangSep 05.2010 — No need for testing; it's been done already: rule 8
Copy linkTweet thisAlerts:
@narutodude000authorSep 05.2010 — You're right, I never thought of caches.

Another question, can PHP files be cached? Both my external Javascript and CSS files are dynamic and are .php.
Copy linkTweet thisAlerts:
@handcraftedwebSep 05.2010 — 
Another question, can PHP files be cached? Both my external Javascript and CSS files are dynamic and are .php.[/QUOTE]


The browser doesn't know that a requested file started as straight HTML or was PHP generated. So looking at rule 8 mentioned in the above post, and following up on the details about rule 8, it seems likely that external CSS and JS files generated by PHP (or whatever) are likely to be cached.

...Mike
×

Success!

Help @narutodude000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...