<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alexandru Dinulescu&#039;s Thoughts&#187; Firefox</title>
	<atom:link href="http://alexdweb.com/blog/tag/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexdweb.com/blog</link>
	<description>This blog is about everything/anything related to XHTML/CSS and of course my favourite js library, jQuery.</description>
	<lastBuildDate>Thu, 09 Dec 2010 12:04:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Preloading CSS Images with CSS 2.1 and CSS 3.0</title>
		<link>http://alexdweb.com/blog/2010/01/07/preloading-css-images-with-css-2-1-and-css-3-0/</link>
		<comments>http://alexdweb.com/blog/2010/01/07/preloading-css-images-with-css-2-1-and-css-3-0/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 15:36:07 +0000</pubDate>
		<dc:creator>Dinulescu Alexandru Adrian</dc:creator>
				<category><![CDATA[XHTML/CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Images]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[Webkit]]></category>

		<guid isPermaLink="false">http://alexdweb.com/blog/?p=174</guid>
		<description><![CDATA[Hello. I was trying to figure out a way to preload CSS images, by javascript or CSS. Unfortunately all the methods I found are not effective, since even tho the images are loaded, when the CSS part that contains an image which is not accessible when the site first opens, it still requires it and [...]]]></description>
			<content:encoded><![CDATA[<p> Hello. </p>
<p> I was trying to figure out a way to preload <acronym title="Cascading Style Sheets">CSS</acronym> images, by javascript or <acronym title="Cascading Style Sheets">CSS</acronym>. Unfortunately all the methods I found are not effective, since even tho the images are loaded, when the <acronym title="Cascading Style Sheets">CSS</acronym> part that contains an image which is not accessible when the site first opens, it still requires it and downloads it. I checked the net panel in firebug and it wasnt very pretty. </p>
<p> However these methods do work if you try to load images into an &lt;img&gt; tag: </p>
<p><span id="more-174"></span></p>
<h3> CSS 2.1 Method </h3>
<p> Using <acronym title="Cascading Style Sheets">CSS</acronym> 2.1 the method is pretty simple. It takes advantage of the <code class="codecolorer css default"><span class="css"><span style="color: #00AA00;">:</span>before</span></code> and <code class="codecolorer css default"><span class="css"><span style="color: #00AA00;">:</span>after</span></code> pseudo classes, and the <code class="codecolorer css default"><span class="css"><span style="color: #000000; font-weight: bold;">content</span></span></code> property. Although this property is pretty limited in what it can do, it does what we need. </p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.pageWrap</span><span style="color: #3333ff;">:after</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;./absolute/path/to/image OR ./relative/path/to/image based on the HTML <br />
file itself rather than the CSS file. (if it doesnt work try with absolute pathing). ex:<br />
&nbsp;url(&quot;</span>./stuff.jpg<span style="color: #ff0000;">&quot;) url(&quot;</span>./stuff2.jpg<span style="color: #ff0000;">&quot;) url(&quot;</span>./stuff3.jpg<span style="color: #ff0000;">&quot;); <br />
/* Important make sure you dont use &quot;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">&quot; to separate the urls */<br />
display: none;<br />
}</span></div></div>
<p> We load the images and then we use display: none so they dont show up, but they are cached so when you load the image within a &lt;img&gt; tag it will show up instantly. </p>
<p> The benefits of this method is that it has a fairly wide acceptance among browser vendors, IE8/Firefox 2+/Google Chrome 1+/Safari 3+. For Previous IE versions you could load up a <acronym title="Javascript">JS</acronym> preload. </p>
<h3> CSS 3.0 Method </h3>
<p> Using the <acronym title="Cascading Style Sheets">CSS</acronym> 3.0 is even simpler, it takes advantage of the modifications done to the <code class="codecolorer css default"><span class="css"><span style="color: #000000; font-weight: bold;">background</span></span></code> property by being able to load multiple images with 1 element. Regardless of what the browser can support we can always create a dummy element and load all the images and then give it a <code class="codecolorer css default"><span class="css"><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span></span></code> we need to use in a &lt;img&gt; tag. </p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.el</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;./images/image1.jpg&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> <br />
&nbsp; &nbsp;<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;./images/image2.jpg&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> <br />
&nbsp; &nbsp;<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;./images/imageN.jpg&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></div></div>
<p> The huge downside of this method is that currently only Google Chrome 4 and Safari 4 support these improvements to the <code class="codecolorer css default"><span class="css"><span style="color: #000000; font-weight: bold;">background</span></span></code> property. Firefox is due to support them in Firefox 3.6 which at the time of this post is in beta 5 so it will be released in 2-3 weeks. IE will probably support <acronym title="Cascading Style Sheets">CSS</acronym>3 properties when IE9 will be available, which according to the IEBlog will happen in a year or so. </p>
<p> I am still looking for a way to preload <acronym title="Cascading Style Sheets">CSS</acronym> images into play, so when they are requested again, they will use their cached versions instead of being downloaded again. </p>
]]></content:encoded>
			<wfw:commentRss>http://alexdweb.com/blog/2010/01/07/preloading-css-images-with-css-2-1-and-css-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

