3

Is there a possibility to check if all of the background images exist in a CSS file?

Without using every selector on the page so that this appears in Firebug NET tab.

Christoph
  • 50,121
  • 21
  • 99
  • 128
John Magnolia
  • 16,769
  • 36
  • 159
  • 270
  • you have to check the correct path of images in css files... – SaurabhLP Jul 16 '12 at 07:57
  • You said it yourself..check if your images are loading from Firebug NET tab.
    Another silly way would be to go to your Styles Tab and hover over each of the background images specified in your css...if the path isn't correct..it'll say 'Failed to load the image'
    – AdityaSaxena Jul 16 '12 at 07:59
  • Maybe use jQuery? http://stackoverflow.com/questions/3381663/check-if-image-exists-with-given-url-using-jquery http://stackoverflow.com/questions/3327655/jquery-check-if-image-exists – thatuxguy Jul 16 '12 at 07:59
  • It would take a few hours to go through ever background in my CSS file, I like to keep all of the CSS for my plugins in 1 file. I just want to check if there are any missing images – John Magnolia Jul 16 '12 at 08:01
  • @Aditya "without using every selector" -> not all images will be requested. You have to check the paths programatically on serverside or iterate over all rules via javascript which is a bit tedious. – Christoph Jul 16 '12 at 08:04
  • @Christoph okay..you know what the best thing about this Forum is...that while understanding problems and providing solutions, you also learn a lot :) Go StackOverFlow :) – AdityaSaxena Jul 16 '12 at 08:19

1 Answers1

2

There is no in CSS way to do this, since the standard says that "an image that is empty (zero width or zero height), that fails to download, or that cannot be displayed (e.g., because it is not in a supported image format) [...] draws nothing" (cite).

You have to parse your CSS file and check all paths. You could do this with JavaScript in your browser, however I believe it's easier to write a Python script or even a small binary application that parses your CSS files and checks whether the files actually exists.

Zeta
  • 103,620
  • 13
  • 194
  • 236
  • Ok I did think that this would be possible without parsing the whole CSS file. Would you suggest doing something similar to this: http://stackoverflow.com/a/3299703/560287 – John Magnolia Jul 16 '12 at 08:30