是否下载了未使用的CSS图像?

浏览器下载了未使用的CSS图像还是将其忽略?


例如。在不符合任何元素的CSS规则中。


.nothingHasThisClass{background:url(hugefile.png);}

还是这取决于浏览器?


三国纷争
浏览 453回答 3
3回答

函数式编程

这将取决于浏览器,因为这是他们决定实施规范的方式,但是在此处进行快速测试:Chrome:不会FireFox:不Safari:不会IE8:不会IE7:不会IE6:未知(有人可以测试并发表评论吗?)

繁星淼淼

不,它们不会下载,至少不会在Firefox,IE8和Chrome中下载。一种简单的测试方法:<!DOCTYPE html><html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp;<style type="text/css">&nbsp; &nbsp; &nbsp; &nbsp; .nonexistent {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background: url('index.php?foo');&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; </style>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body><?php if(isset($_GET['foo'])) {&nbsp; &nbsp; file_put_contents('test.txt', $_SERVER['HTTP_USER_AGENT']);} ?>&nbsp; &nbsp; </body></html>如果test.txt使用浏览器的用户代理填充,则将下载图像。在我的任何测试中都不是这种情况。
打开App,查看更多内容
随时随地看视频慕课网APP