Welcome to WebmasterWorld Guest from 54.147.189.54

Forum Moderators: not2easy

Message Too Old, No Replies

page with multi php includes() each referencing the same file.css

php includes css optimization

     
7:20 am on Jan 3, 2010 (gmt 0)

New User

5+ Year Member

joined:Aug 20, 2008
posts:14
votes: 0


Hi. My site uses a template that uses php includes to create a navbar, mainbar, side column and footer. I then also use php includes in each of those to reference particular widgets or content. I.e the sidebar might use an includes to incorporate commercial ads, sponsorships, alerts and navigation. So just for the sidebar I'd including 4 documents. Each of those 4 documents has a line: <link rel="stylesheet" type="text/css" href="/css/master.css">

Then the sidebar.php file might also have the line: <link rel="stylesheet" type="text/css" href="/css/master.css">

The homepage which uses a php inclues to suck in the sidebar.php will also have the line: <link rel="stylesheet" type="text/css" href="/css/master.css">

So when I read the source for my page from a browser I see sometimes dozens of references to loading master.css.

Is this a problem? Will these multiple reads slow the page down significantly? Is it worth the agravation of devising a method of recoding the whole site to remove this issue? I like having the css in each document for testing.

Any input would be appreciated.

12:04 pm on Jan 4, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2002
posts:2204
votes: 0


There's no need to apply it to each include. Just place this:

<link rel="stylesheet" type="text/css" href="/css/master.css"> in your pages <head></head>.

As includes are rendered on the server, before the CSS is applied, there is no real point in adding it inline as well. Lucky for you it's a quick change to each include, not to dozens of pages :)

6:55 am on Jan 9, 2010 (gmt 0)

New User

5+ Year Member

joined:Aug 20, 2008
posts:14
votes: 0


1) The reason I like having the css attached to each include is so I can preview the styling of each module independent of an index page. Its very helpful to catch errors and troubleshoot as well.

2) my real concern is that the css file that each of the 20 includes that make up a page references is being read in by the browser 20 times. So onload is the browser reading and caching the first instance and ignoring the additional 19 calls or is it reloading it and comparing the file 20 times for a single page load?

Thanks!

9:35 am on Jan 9, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2002
posts:2204
votes: 0


One load (then cache). Just 19 extraneous lines of code.

I'd create a test page with the css file in the head, and load the php includes into it.

I think it definitely makes sense to remove each call from the 'live' includes - it's doing you no favors :)

8:59 pm on Jan 15, 2010 (gmt 0)

New User

5+ Year Member

joined:Aug 20, 2008
posts: 14
votes: 0


Thanks limbo. And its still going to be 1 load then cache for all browsers?

If that's the case then its probably not worth the work right now just to save on 19 lines of code.

Just wanted to make sure that it wouldn't be resulting in 19 extra http requests!

-D

5:28 am on Jan 18, 2010 (gmt 0)

Full Member

5+ Year Member

joined:Jan 29, 2007
posts:228
votes: 0


Even though it does not download the stylesheet more than once (if it is cached), the browser will still parse the file, hence slowing down the page.

Just something to keep in mind...

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members