News for hackers. Stuff that matters.
Re:JSZip: Create, read and edit .zip files with JavaScript by nanidin on Saturday April 19, 2014 @11:23PM (#7615710)
Potential use case: instead of using CSS sprite maps (putting all of your images into one image to reduce the number of http requests generated by your page, then using css magic to select regions inside of that image), image files could be zipped into an image package that is delivered to the client, who unzips it and uses the images inside. This would cut down on the number of requests made, but allow the images to be used as normal images instead of as images within a sprite sheet.
Re:JSZip: Create, read and edit .zip files with JavaScript by moron4hire on Sunday April 20, 2014 @12:08AM (#7615813)
The crazy thing: in this thread, you are all right. The state of sending multiple files sucks. ZIP is the closest thing we have to a universal standard, if only because Windows refuses to ship with support for anything that is meaningful.
Re:JSZip: Create, read and edit .zip files with JavaScript by zo1 on Sunday April 20, 2014 @07:33AM (#7616491)
I seem to recall them getting a big fat law suit when they tried to bundle things with their OS. Perhaps they don't bundle things anymore for a reason?
Re:JSZip: Create, read and edit .zip files with JavaScript by TazeTSchnitzel on Sunday April 20, 2014 @10:52AM (#7616933)
Well, is there anything better for Windows, aside from maybe cabinet files?
Re:JSZip: Create, read and edit .zip files with JavaScript by chadscira on Saturday April 19, 2014 @11:29PM (#7615725)
i'm surprised we don't have a cross-browser webarchive concept yet... especially with the emphasis on mobile.
Re:JSZip: Create, read and edit .zip files with JavaScript by dsl on Sunday April 20, 2014 @01:23AM (#7615965)
We have a fantastic one based on MIME that is usable by everything except Firefox (however you need to enable some experimental stuff in Chrome).

http://en.wikipedia.org/wiki/MHTML

Re:JSZip: Create, read and edit .zip files with JavaScript by TazeTSchnitzel on Sunday April 20, 2014 @10:47AM (#7616914)
Until now I always thought the M stood for Microsoft. Now I know.
Re:JSZip: Create, read and edit .zip files with JavaScript by chadscira on Sunday April 20, 2014 @04:04AM (#7616204)
i wasn't aware of this, very cool
Re:JSZip: Create, read and edit .zip files with JavaScript by stu_k on Sunday April 20, 2014 @04:04AM (#7616208)
There is definitely work towards this. This spec was recently released and has some potential: https://github.com/w3ctag/packaging-on-the-web
Re:JSZip: Create, read and edit .zip files with JavaScript by jahitr on Saturday April 19, 2014 @11:39PM (#7615755)
Some images formats already come with compression. Also, zip doesn't work with well with binary data. Using CSS to "subscript" into the sprite is a better solution.
Re:JSZip: Create, read and edit .zip files with JavaScript by nanidin on Sunday April 20, 2014 @12:05AM (#7615805)
It's not about saving bandwidth or space by compressing the images - it's about removing the step of combining your images into one big image then using coordinates inside of that image to find your original images.

Sure, you can build the spriting into your build process, but I don't know how to do that (I'm sure there are tools) and you can't exactly use normal css since the coordinates of your images may change within the sprite sheet.

Using the zip method saves you some of that headache/overhead with the tradeoff of having to package your images into a zip and unzip them on the client side.

Re:JSZip: Create, read and edit .zip files with JavaScript by deathcap on Sunday April 20, 2014 @01:07PM (#7617536)
> Using the zip method saves you some of that headache/overhead with the tradeoff of having to package your images into a zip and unzip them on the client side.

I wrote an NPM module recently using this exact technique, https://github.com/deathcap/artpacks (for use in the browser with browserify). Had a bunch of small textures, originally I was requesting each individually in their own HTTP request, but zipping them up and extracting in the browser led to a fairly significant improvement in latency.

Packing all of the small textures into one big image and slicing it up at runtime was also an option I considered. In fact, since I'm using these textures with WebGL they actually are packed into one large texture atlas before uploading to the GPU, then indexed at runtime using UV coordinates. So one could stitch together all the textures beforehand, distributing a prebuilt texture atlas as a single file over HTTP — this may slightly improve performance, but it has another disadvantage.

Flexibility. For my purposes, it makes more sense to build up the atlas dynamically at runtime, since you might not know exactly what textures are needed and when (due to the nature of my application). Also, I wanted to support "cascading" textures, where multiple packs are loaded each providing possibly a subset of all textures, and the first pack with a matching texture takes priority. With unzipping at runtime in the browser, this technique was very easy to implement (without the latency cost of individual texture file requests).

And for compatibility with img src, and other HTML file references, I just convert the unzipped file to an HTML5 Blob then request its 'blob:' URI. 'data:' URIs would also work, but blobs are widely supported by modern browsers (unlike 'filesystem:' URLs, for the Web Filesystem API supported by Chrome) and don't need to encode the full file contents in the URL. The complete process, including unzipping, matching, blobbing, all happens fairly fast, have not ran into any noticeable performance issues.

(Note: technically I'm not using Stuart Knightley's JSZip, but Kris Kowal's zip module https://www.npmjs.org/package/zip - I can't recall why as they are both available on NPM, but its the same idea).

Re:JSZip: Create, read and edit .zip files with JavaScript by MatmaRex on Sunday April 20, 2014 @06:08AM (#7616385)
You can embed the images in the CSS as data: URIs, preferably automatically as part of the build process, and get the best of both worlds.
Re:JSZip: Create, read and edit .zip files with JavaScript by TheZenPsycho on Saturday April 19, 2014 @11:50PM (#7615780)
Except that the primary utility of zip is usually not its compression. It's the combining of multiple files into one "file". Basically what tar was invented for, but with actual universal support on every OS.
Re:JSZip: Create, read and edit .zip files with JavaScript by chadscira on Sunday April 20, 2014 @12:18AM (#7615832)
seems like multipart http responses may be pretty close to what we want
Re:JSZip: Create, read and edit .zip files with JavaScript by TheZenPsycho on Sunday April 20, 2014 @05:50AM (#7616363)
a multipart http response saves what kind of file?
Re:JSZip: Create, read and edit .zip files with JavaScript by csomar on Sunday April 20, 2014 @06:43AM (#7616433)
So is the point to simplify the process or something else?

CSS Sprites are very easy to make and use. You just need to set the right coordinates for the background-image.

On the other hand, running a complicated JS library and building an infrastructure to extract these images seems like an overkill for something that CSS sprites can do so easily.

Re:JSZip: Create, read and edit .zip files with JavaScript by TazeTSchnitzel on Sunday April 20, 2014 @10:39AM (#7616892)
CSS Sprites have numerous disadvantages that normal image files lack.
Re:JSZip: Create, read and edit .zip files with JavaScript by magicalist on Sunday April 20, 2014 @03:35PM (#7618181)
I'm surprised that no one has brought up that this is also solved at the protocol level with SPDY and eventually HTTP 2 (and by HTTP pipelining, which is sadly never going to happen). Not a silver bullet, but a bit more sane than unzipping a set of images in JS.