About this article
This article is created using an automated generation workflow powered by generative AI. Referring to the official JSZip documentation, we prepared a static tutorial that generates a ZIP file from short, fictitious notes directly in the browser.Verification Status: 🧪 Input processing tested, ZIP generation in the browser unverified
We verified 9 logic tests in Node.js, including fixed filenames and input constraints. Deployment to GitHub Pages, actual ZIP generation, downloading, and extraction have not yet been confirmed.
Bundling Notes into a ZIP with JSZip: An Experiment Creating 2 to 3 Files on a Static Web Page
When you want to bundle multiple texts into a single ZIP file, is it always necessary to upload them to a server? If you are only handling short texts, there isa method to generate ZIPs within the browser. By using the JavaScript library JSZip, you can specify filenames and content to bundle them without having to implement the internal ZIP structure or compression processing from scratch.
This tutorial does more than just create a button that outputs a ZIP file.The process of creating files, the user's download action, and post-save managementare designed to help you experience that these are separate steps. It does not read existing files and only uses fictitious notes.
- Try it first: Live Demo
- Experimental Conditions
- What JSZip is responsible for
- Blob and temporary download URL
- Reason for Fixing File Names
- Change only one condition and observe
- Troubleshooting when things do not work
- Precautions before adopting in production
- Summary
- Official Documentation and Samples
- Verification and Unverified Items
Try it first: Live Demo
Static JSZip Live Demo(Public URL and browser operations unverified this time)
When the demo screen opens, check the fictitious notes prepared as initial values and click "Create ZIP". The generated ZIP is designed to containREADME.txtfor explanatory purposes andmemo.txtstoring the input. This is the firstfiles.
Next, select "Include Checklist.txt" and click the button again.checklist.txtadded3 filesis the expected result. The screen displays the included file names and the ZIP size in bytes. To actually download, click the separately displayed "Download ZIP" link.
Please distinguish this order.Completion of ZIP generation does not mean completion of saving to the device.The destination folder also depends on the user's browser settings. The system is not designed to display "Saved to computer" just upon generation.
Experimental Conditions
| Item | Content |
|---|---|
| Library Used | JSZip v3.10.2 |
| Delivery Architecture | Static delivery of HTML, CSS, and JavaScript via GitHub Pages |
| External CDN at Runtime | Not required. Library bundled invendor/ |
| Input | Fictional text within 200 characters |
| Contents of the ZIP | README.txt、memo.txt, optionallychecklist.txt |
| Read existing files | Do not |
| External APIs and databases | Do not use |
| Execution check | 9 input validation and filename logic items. ZIP binary generation unverified |
A static site does not mean that the display never changes. Even if the files served from the server are static, the browser can execute JavaScript to dynamically change the contents and size of the ZIP. The network communication required to open this demo and the ZIP generation process triggered after clicking the button are separate.
What JSZip is responsible for
How to add content to a ZIPzip.file(name, content)is used. This allows you to register files to be placed inside the ZIP. This is not a command to write files directly to Windows Explorer or similar tools.
const zip = new JSZip();
zip.file("README.txt", "架空の説明文\\n");
zip.file("memo.txt", "架空の作業メモ\\n");
const blob = await zip.generateAsync({
type: "blob",
compression: "DEFLATE"
});
generateAsync()starts the generation of the entire ZIP and returns the result asynchronously.type: "blob"is the specification to receive it in a Blob format that is easy to handle in the browser.compression: "DEFLATE"specifies the compression format. Since library processing is asynchronous, it is important not to enable the save link before completion.
Note that grouping two identical files does not double the size. A ZIP contains management information such as headers, and the more duplicated the text is, the more likely it is to be compressed. Since the size after compression varies depending on the input content, a specific byte count is not stated as an absolute measured value in the article.
Blob and temporary download URL
Once the ZIP Blob is created, useURL.createObjectURL(blob)to create a temporary URL within the browser and linkhrefis assigned to. For the link'sdownloadattribute, specify a fixed name for educational materialsdaily-code-demo.zip.
If you generate the ZIP again, release it withURL.revokeObjectURL()so that the previous temporary URL is not left behind. Code is also included to attempt release when leaving the page. However, details of memory release in the user's browser or operating system were not verified on actual devices this time.
If the browser indicates that "generation succeeded but the file cannot be found," first check whether the download link was clicked and where the save destination is configured. It is important not to confuse the issue of whether the ZIP could be generated with the issue of whether it could be saved to the device.
Reason for Fixing File Names
In this implementation, users can modify the memo text, but thefile names included in the ZIP are not free-form inputs.README.txtThere are only three types:memo.txta fixedchecklist.txt, and additional ones if needed. This not only simplifies the explanation of how the educational material works, but also avoids handling unnecessary file names and paths.
For example, even if you write../secret.txtin the input field, that string becomes the text insidememo.txtand is not used as a path name inside the ZIP. If the ZIP name were directly constructed from user input, other risks would need to be considered, such as path separators, absolute paths, and extraction into unintended folders.
Furthermore, the educational material's input processing rejects non-string data and returns an error if it exceeds 200 characters. Whilemaxlengthis also present on the screen, verification is performed in the logic as well rather than relying solely on it.Input restrictions on the screen and boundary checks inside the program are separate. This makes the logical assumptions easy to understand even if additional buttons or callers are introduced in the future.
Change only one condition and observe
First, create the ZIP file with the checkbox unchecked, then change it to checked. The number of included files will change from two to three. This is due to the addedchecklist.txt. On the other hand, in the comparison where the note length is increased, the filecountremains the same, while the content and compressed size change.
This distinction is also important when developing export functions in practice. Ensure that you can verify separately whether the number of files has increased, the content of each has grown, or the options selected by the user have increased. If you change multiple conditions at the same time, it becomes impossible to determine which factor caused the ZIP contents to change.
In addition, the tests this time verified items such as "the list of filenames resulting in 2/3 items," "boundary values," "empty strings," "rejection of non-string values," and "handling of 200 characters including emojis."This is not proof that the ZIP binary was actually generated and extracted in the browser.
Troubleshooting when things do not work
| Observed issue | Verification point | Action |
|---|---|---|
| Page does not open | GitHub Pages publication settings and URL | Check the HTML and file layout from the README |
| Generation button cannot be used | vendor/jszip.min.jsWhether the script was loaded successfully | Check the relative paths of the distributed files |
| Input is rejected | Check if it exceeds 200 characters | Revert to a fictional short sentence and test again |
| No download link is available | Verify whether the ZIP generation succeeded | Check the displayed message and the Console |
| The downloaded item cannot be found | Check the save location and the browser download settings | Check the browser download history |
| The ZIP file seems larger than expected | Input text, additional files, and compression format | Compare with the same short text to narrow down the cause |
When opening a local HTML filefile://, JavaScript modules may fail to load due to CORS restrictions. Please follow the instructions in the course README to open it via a static HTTP server. There is no need to add a new database or a production PHP server.
Precautions before adopting in production
While JSZip is convenient,it does not automatically guarantee ZIP encryption, malware scanning, or destination permission management. This demo only bundles short dummy strings. Do not enter real customer names or contract details. Avoid assuming that simply archiving confidential files into a ZIP makes them safe to share.
For business use, consider output allowlists, size limits, character encodings, filename normalization, read-back verification after creation, and destination access controls. Batch-generating large files entirely within the browser also introduces memory and processing time constraints. Do not assume that this small-scale 200-character experiment can be directly scaled up to generate massive backups.
Additionally, text included in the generated ZIP can be extracted and read by the recipient. The ability of a library to generate ZIP files is distinct from the protection of sensitive information. Secure file sharing requires designing separate safeguards for transmission protection and access control.
Summary
By including JSZip, you can build a ZIP generation feature that bundles multiple texts even on a static web page. Start by creating it with two items, then modify only the checkboxes to try it with three.Register files, generate the ZIP, and proceed to the save operationOnce you grasp these distinct roles, it becomes easier to understand how to use the library.
Official Documentation and Samples
Static live demo(Publishing and browser operations are unverified)
Verification and Unverified Items
On Node.js v22.16.0, we ran input functions and tests where the GitHub materials and Git blob SHA match, passing all 9 cases. We also verified that the version-fixed JSZip v3.10.2 and the license file match the Git blob SHA of the distribution source. GitHub Pages reachability, actual ZIP binary generation/saving/extraction, actual browser UI, and WordPress rendering remain unverified.
