Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Create .zip files with JavaScript dynamically

Saturday, March 23rd, 2019 by Servage

The JavaScript library JSZip provides you with the ability to generate .zip files dynamically. This way you can send lots of data to a user in a convenient and bandwidth-saving way. With JavaScript becoming more and more powerful, and the amount of data handled by JavaScripts increasing every day, this is a great way to communicate with the user. Most users generally accept zip files from trusted sites – assuming that your users trust your site ;-)

It’s really easy to create a .zip file. Check out this sample code:

var zip = new JSZip();
zip.add("Hello.txt", "Hello World\n");
img = zip.folder("images");
img.add("smile.gif", imgData, {base64: true});
content = zip.generate();
location.href="data:application/zip;base64,"+content;

Creating zip files in the browser with JavaScript also removes some of the resource-consumption from your server.

Read more and download the library from JSZip.

Create .zip files with JavaScript dynamically, 2.9 out of 5 based on 13 ratings
Categories: Tips & Tricks

Keywords:

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.