How to download generated zip files in Javascript
In this tutorial, we will learn how to create and download the zip file using javascript.
Scenario.
Let’s assume we have a task to download the zip file of 6 images. The user will click the button “Download zip file” and the zip file of 6 images will be downloaded to the user’s device. Here we will read the images from the URL and download those images in a zip file.
Let’s move toward the coding part.
First, create a basic button to download a zip file with on click event.
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="generateZIP()">Download Zip File</button>
<script>
async function generateZIP(){
}
</script>
</body>
</html>
Now go to the JSZip page and download dist/jszip.js
or dist/jszip.min.js
manually and add these two files to your project folder.