Home › All Tools ›

JS Compression Tool

Use JS Compression Tool online for free at FreeToolZones — no sign-up, no watermark.

Loading tool...

The JS Compression Tool on FreeToolZones compresses JavaScript code with gzip in your browser, and decompresses gzip files back to readable text, without uploading anything. Compression is the step that turns a good file size into a great one: where minification removes characters a browser does not need, gzip finds repeated patterns in what remains and represents them compactly, often cutting the transfer size by more than half. Servers normally apply gzip automatically, but there are many moments when you want to compress a file yourself, measure the result, or recover the contents of a gzip file you received. This tool handles both directions, with clear size statistics and downloads for the results.

Understanding compressed size matters because it is the size that actually travels across the network. A file that looks large on disk may compress well because it repeats the same identifiers and keywords, while a file full of unique strings may compress poorly. Measuring the gzip size of your code, before and after changes, tells you whether an optimization helped where it counts. This tool gives you that measurement, plus the compressed file itself, using the browser CompressionStream API, which is the same gzip algorithm servers use.

What Is the JS Compression Tool?

The JS Compression Tool is a free online tool with two modes, selected from a menu. In Compress to gzip mode, it takes JavaScript code from the text box or from a chosen file, compresses it with gzip, shows the original size, the compressed size, and the percentage saved, and offers the compressed file for download. In Decompress a .gz file mode, it takes a chosen gzip file, decompresses it, shows the result as text with the compressed and decompressed sizes, and offers the recovered text for download. Both modes run entirely in the browser: the page states that compression happens in the browser and nothing is uploaded, and the same local processing applies to decompression.

Compression input is flexible. You can paste code into the text box, which is labeled JavaScript code and accepts any text, or you can choose a file with the file picker, which accepts .js, .mjs, .txt, .json, and .css files in compress mode. When both are present, the chosen file takes precedence: the file bytes are compressed, and the text box is ignored. That precedence rule is stated in the hint under the file picker, so there is no ambiguity about which input will be used. The Load sample button fills the text box with a short example script, so you can compress something immediately and see the statistics without preparing input.

The download name follows the input. When a file was compressed, the download is named after that file with .gz appended, so script.js becomes script.js.gz. When text was compressed, the download is named compressed.js.gz. The statistics use human-readable sizes, showing bytes, kilobytes, or megabytes as appropriate, and the percentage saved is never negative: if compression somehow made the data larger, which can happen with tiny or already-random inputs, the savings figure shows zero rather than a negative number.

Decompression mode changes the interface to match its needs. The text box is hidden, because decompression input comes only from a file. The file picker switches to accepting .gz files only. The main button changes its label from Compress and Download .gz to Decompress. Choosing a file is required: pressing Decompress without one produces a message asking you to choose a .gz file. The decompressed bytes must be valid UTF-8 text, or decompression fails with a message saying so, because the tool displays the result as text. The recovered text is shown on the page with its sizes, and the download is named after the input file with the .gz suffix removed, falling back to decompressed.txt if removing the suffix leaves nothing.

Browser support is a stated requirement. The tool needs the CompressionStream and DecompressionStream APIs, available in current versions of Chrome, Edge, Firefox, and Safari. If either API is missing, the page shows a notice explaining the requirement and suggesting an update or a different browser, instead of presenting controls that cannot work. That honest behavior is preferable to a silent failure, and it tells you immediately whether your browser can do the job.

How to Use the JS Compression Tool

The steps differ by mode. Follow the set that matches what you want to do.

  1. Choose a mode. Use the Mode menu to pick Compress to gzip (.gz) or Decompress a .gz file. The page adjusts itself: in decompress mode the text box hides, the file picker accepts only .gz files, and the main button reads Decompress. Switching modes clears any previously chosen file, so you always choose fresh input for the new mode.
  2. Provide input for compression. In compress mode, paste code into the JavaScript code box, or choose a file with the picker, which accepts .js, .mjs, .txt, .json, and .css files. If you choose a file, it takes precedence over the text box. If you provide neither, the tool asks you to paste code or choose a file.
  3. Provide input for decompression. In decompress mode, choose a .gz file with the picker. There is no text input in this mode. Pressing the button without a file produces a message asking you to choose one.
  4. Run the tool and read the statistics. Press the main button. For compression, the statistics show the original size, the compressed size, and the percentage smaller. For decompression, the recovered text appears with the compressed and decompressed sizes. Errors explain the problem, such as invalid gzip data or decompressed bytes that are not valid UTF-8 text.
  5. Download the result. For compression, press the Download button, which names the file after your input with .gz appended, or compressed.js.gz for pasted text. For decompression, press the Download button, which names the file after the input with .gz removed. The Load sample button, available in compress mode, fills the text box with example code for a quick trial.

After compressing, verify the result by decompressing it: switch to decompress mode, choose the downloaded .gz file, and confirm the recovered text matches your original code. That round trip confirms the gzip file is valid and complete, which matters if the file will be stored, sent, or served to browsers. A compressed file that fails to decompress is worse than no compression at all, and the check takes seconds.

Key Features of the JS Compression Tool

The features below describe the two modes, the input handling, and the browser requirement.

Gzip compression with real statistics

Compression uses the gzip format through the browser CompressionStream API, the same format web servers use for content encoding. The statistics show original size, compressed size, and percentage saved in human-readable units, so the benefit is visible immediately and honestly, including the zero floor for inputs that do not shrink.

Gzip decompression to readable text

Decompression uses the DecompressionStream API and displays the recovered text on the page, with both sizes shown. The UTF-8 requirement ensures the displayed result is genuine text, and the error message for non-text results explains the situation instead of showing corrupted characters.

Text and file input with clear precedence

Compress mode accepts pasted text and files, with a chosen file taking precedence over the text box. The accepted extensions are listed on the picker and in the hint, and the picker accept list changes with the mode, so the file dialog shows only relevant files. Mode switching clears the chosen file to prevent stale input from being used by mistake.

Meaningful download names

Compressed downloads append .gz to the source file name, or use compressed.js.gz for pasted text. Decompressed downloads remove the .gz suffix, or use decompressed.txt as a fallback. Sensible names mean the downloaded files are ready to use without renaming.

Honest browser support handling

When the required APIs are unavailable, the tool shows a notice naming the requirement and the browsers that support it, rather than presenting broken controls. That behavior respects your time and tells you exactly what to do next.

Practical Use Cases

Compression and decompression are infrastructure operations that appear in deployment, measurement, archiving, and debugging. The examples below show where a browser-based tool fits.

Measuring the real download size of code

The gzip size is the size that matters for page load, and it often differs surprisingly from the file size. Compressing a script here shows the size a server would send with gzip enabled, which lets you compare versions, evaluate whether minification helped, and decide whether a dependency is worth its weight. The percentage saved figure makes the comparison immediate.

Preparing a compressed file for manual deployment

Some hosting setups, content delivery configurations, and static file workflows accept pre-compressed files. Compressing a script here and downloading the .gz file gives you an artifact you can upload alongside or instead of the original, following the conventions of the system you deploy to. Verifying the download by decompressing it here first is a sensible precaution.

Recovering the contents of a gzip file

A .gz file received from a colleague, downloaded from a server, or found in an archive can be inspected here without command-line tools. Decompressing it shows the text and lets you download the recovered file, which is useful when you need to read the contents, check what version of a script was deployed, or recover source from a compressed backup.

Comparing minified and unminified sizes fairly

Minification savings look large in raw bytes but smaller after gzip, because gzip already exploits repetition. Compressing both versions here shows the true difference in transfer size, which is the number that should drive the decision. That comparison often shows that minification still helps, but by less than the raw figures suggest, and it grounds the discussion in measured data.

Learning how gzip behaves on different inputs

Compressing varied inputs teaches the intuition behind compression: repetitive code compresses well, unique random-looking text compresses poorly, and tiny inputs may not shrink at all because the gzip header and structure have a fixed cost. The sample script, the statistics, and a few experiments with your own code build that intuition faster than reading about the algorithm.

Tips and Best Practices

  • Measure gzip size, not just file size. The compressed size is what users download. Use it to judge optimizations, compare versions, and decide whether a change was worth making.
  • Verify every compressed file by decompressing it. A round trip here confirms the .gz file is valid and complete. Never deploy or send a compressed file you have not verified.
  • Remember that a chosen file beats the text box. In compress mode, if you pick a file after pasting text, the file is what gets compressed. Clear the file choice or switch modes if you meant to compress the pasted text instead.
  • Combine minification with compression. Minify first to remove unneeded characters, then compress to squeeze what remains. The two steps multiply, and measuring both shows the combined benefit.
  • Do not expect every input to shrink. Very small inputs and inputs with little repetition may compress to nearly the same size or slightly larger. The zero-floored savings figure reflects that honestly.
  • Check browser support before relying on the tool. Current Chrome, Edge, Firefox, and Safari support the required APIs. If you see the unsupported notice, update the browser or switch to one that supports compression.

Limitations

The tool compresses with gzip only. It does not offer other formats, compression levels, or dictionary options, and it does not create archives containing multiple files: one input produces one gzip stream. Decompression requires valid gzip data and valid UTF-8 text output, so binary gzip content, such as a compressed image, cannot be displayed, and corrupted gzip files fail with an error rather than a partial result. The tool does not serve files, set content encoding headers, or configure a server: it produces and reads gzip files, and deployment remains your responsibility.

Browser support is a hard requirement: without CompressionStream and DecompressionStream, the tool shows a notice and no controls. The tool processes one input at a time, so batch compression of many files is better done with a build step or a command-line tool. Very large files are limited by browser memory and by the file reading step, and the text display for decompressed output suits code and text files rather than huge documents. Finally, compression is not encryption: gzip output is easily decompressed by anyone, and it provides no confidentiality.

Frequently Asked Questions

Why does compression show zero percent smaller for my input?

Some inputs do not shrink: very small inputs carry the fixed gzip overhead, and random-looking inputs have little repetition to exploit. The savings figure never goes below zero, so a result of zero means the compressed size was equal to or larger than the original.

I pasted text and chose a file. Which one was compressed?

The file. In compress mode, a chosen file takes precedence over the text box, as the hint states. To compress pasted text, do not choose a file, or switch modes and back to clear the file choice.

Why does decompression fail with a UTF-8 error?

The decompressed bytes are not valid UTF-8 text, which usually means the gzip file contains binary data rather than text. The tool displays results as text, so it reports the problem instead of showing corrupted characters.

Why do I see a notice instead of the tool?

Your browser lacks the CompressionStream or DecompressionStream API. Current versions of Chrome, Edge, Firefox, and Safari support them. Update your browser or try a different one.

Is gzip the same compression servers use?

Yes. Gzip is the standard content encoding web servers apply to text responses. The size this tool reports is a good estimate of the transfer size a server would produce for the same content with gzip enabled.

Is my code uploaded anywhere?

No. Compression and decompression run entirely in your browser, and nothing is uploaded. The page states this for compression, and the same local processing applies throughout.

Related Tools

These tools prepare code for compression, verify it, and handle the neighboring file operations.

  • JavaScript Minifier – remove comments and unneeded whitespace before compressing, for the smallest transfer size.
  • JavaScript Validator – check the syntax of code before compressing it or after decompressing it.
  • JS Base64 Encoder – encode compressed or binary data as text when a text-only channel requires it.
  • File Size Converter – convert between bytes, kilobytes, and megabytes when comparing sizes.
  • ZIP File Creator – bundle multiple files into a single archive when gzip alone is not enough.

Browse More Tools