<?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>ADM Blog &#187; safari</title> <atom:link href="http://blog.another-d-mention.ro/tag/safari/feed/" rel="self" type="application/rss+xml" /><link>http://blog.another-d-mention.ro</link> <description>No matter how you see things, reality changes when you reach understanding</description> <lastBuildDate>Fri, 22 Jul 2011 06:56:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1</generator> <item><title>Read/Load files from ZIP in JavaScript</title><link>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/</link> <comments>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/#comments</comments> <pubDate>Fri, 01 Oct 2010 10:40:05 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[firefox]]></category> <category><![CDATA[ie]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[load]]></category> <category><![CDATA[opera]]></category> <category><![CDATA[parse]]></category> <category><![CDATA[read]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[zip]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=837</guid> <description><![CDATA[At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in the browser if something goes wrong. So I've made this JavaScript class that comes to help. What can you do is Zip up all your assets (js, images, css) and use ZipLoader class to read the zip and unpack your resources whenever you need them. It's small (10KB), easy to use and quite fast considering the extraction is made by JavaScript.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #006600; font-style: italic;">// loads and caches the zip file</span>
   <span style="color: #003366; font-weight: bold;">var</span> loader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ZipLoader<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a style node in the document header and appends the style</span>
   loader.<span style="color: #660066;">LoadCSS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://style.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a script node in the document header and appends the script</span>
   loader.<span style="color: #660066;">loadScript</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://jquery.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the file content</span>
   <span style="color: #003366; font-weight: bold;">var</span> someFileYouNeed <span style="color: #339933;">=</span> loader.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;files.zip://myFile.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the base64 encoded image usable as img source</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#logo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> loader.<span style="color: #660066;">loadImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://images/logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The level of compression using zip surpasses the js and css minification in all the ways possible. For example, My current application has 79 files (js, and few css) and they all sum up to 924KB in size. Zipping all those 96 files using Ultra compression level gives me 1 file of 126 KB => 1 server request. That's something.</p><p>The best performance is made Opera (strangely), then Firefox, Crome, Safari and last IE (no surprise here, I was expecting it before I even started).</p><p><del
datetime="2010-10-04T10:42:19+00:00">It's a V 1.0 that still needs some work and it doesn't work in IE because that stupid browser overrides the mime type and at first null character in the reading of the zip, the content ends. I will fix this eventually <img
src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Read/Load files from ZIP in JavaScript" class='wp-smiley' title="Read/Load files from ZIP in JavaScript" /> </del> I will also include this as a <a
href="http://code.google.com/p/adm-jclass/">jClass</a> library soon.</p><p><strong>Update:</strong> Fixed it so it works in IE as well. There is a performance issue still. Will fix that too.</p><p>Till then, <a
href="http://another-d-mention.ro/apps/download.php?app=archive">HERE</a> are the sources and a demo.</p><p>The zip in the demo is made using <a
href="http://www.7-zip.org/">7Zip</a> with Ultra Compression level.</p><p>Happy codding.</p><p><a
class="FlattrButton" style="display:none;" href="http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/"></a><br
/> <noscript><a
href="http://flattr.com/thing/183347/ReadLoad-files-from-ZIP-in-JavaScript" target="_blank"><br
/> <img
src="http://api.flattr.com/button/flattr-badge-large.png" alt="flattr badge large Read/Load files from ZIP in JavaScript" title="Flattr this" border="0" /></a></noscript></p><p><script type="text/javascript">google_ad_client = "ca-pub-3771432957882119";
/* InsidePost */
google_ad_slot = "9112434755";
google_ad_width = 468;
google_ad_height = 60;</script><br
/> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/feed/</wfw:commentRss> <slash:comments>50</slash:comments> </item> </channel> </rss>
