1

My background image seems to be loading last. I don't mind the first time, but I was expecting it to be cached, so any subsequent pages that use the same background should be loaded instantly. However the background is only loading once the whole page is drawn.

My css is in the header, most of my js files are at the bottom. (I've kept jquery from cdn in the header too).

The background image, a 1X960 px (2 color gif), is pretty small in size and repeating along Y.

Is there anything I can do to make it load quicker?

To be honest this is noticable in chrome and firefox. In IE8 the backround loads promptly.

smottt
  • 3,272
  • 11
  • 37
  • 44
raklos
  • 28,027
  • 60
  • 183
  • 301

4 Answers4

1

Make the Image Larger

It's only 1px high, some browsers struggle with repeating an image so many times. Try making it 50px high and see if it improves performance. I can't find the answer, but someone showed me once that some browsers really struggle with repeating backgrounds and they use up a huge amount of processing power to render them hundreds of times in repeat.

Different domain

Serving static data from a cookieless domain can improve image loading performance.

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
1

Since you are using VS Dev Server this might be worth a shot if you are using Windows 7 (and maybe Vista) it's to do with some DNS/IPv6 problem taking forever to resolve and was something that was driving me stark raving mad with exactly the same issues until about 5 days ago. It was taking 8 seconds to load a 500k page now it takes 383ms

navigate to your hosts file (C:\Windows\System32\drivers\etc) and check that the second localhost entry is commented out as follows with the # symbol:

# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
#::1             localhost

Commenting out this line fixed the problem instantly - not really sure exactly what the problem was but I know this fixed it.

Rob
  • 10,004
  • 5
  • 61
  • 91
0

Check your cache meta tag, if it's present and set to "no-cache" it may not cache your images.

Also, if your CSS file is very big it will affect the download of your images referenced in the CSS.

jackJoe
  • 11,078
  • 8
  • 49
  • 64
  • if all the OP has are comments he/she can never close/accept the question. – jackJoe Mar 14 '11 at 10:18
  • 3
    Regardless, explain to me how this is an answer? Looks to me like you just asked a question like the rest of us did. – daryl Mar 14 '11 at 10:26
  • @jackJoe, I'm using one css file for the entire site. its 45kb. would it be better to have the css for the background as an inline style? given that the page is drawn, im not sure if this is the problem. Also can you give more info on cache meta tag? – raklos Mar 14 '11 at 13:32
  • the inline style is a good idea for testing at least (I wouldn't use it at the final site), if it works then at least we have another pointer to what may be wrong. As for the meta tag, you have at least two types: pragma and expire, if both are set to expire, it's likelly that your content will not cache (but to be honest I haven't found this to work with CSS images). I suggest you read this about caching: http://www.mnot.net/cache_docs/ – jackJoe Mar 14 '11 at 14:40
  • also, it would be a good idea to check if the image referenced isn't being called in a dynamic way (I've seen something like this is some microsoft devs, such as the images being called via the CSS, but the actual image is "built" dynamically, strange). Also, check if the CSS is also called dynamizally, like thecssfile.css?someMSQuery=somethingRandom this may also cause the CSS to be called fresh everytime and may slow the images. – jackJoe Mar 14 '11 at 14:43
0

A combination of all these answers helped. I have voted them all up.

raklos
  • 28,027
  • 60
  • 183
  • 301