{"id":10761,"library":"downloadjs","title":"download.js: Client-Side File Download","description":"Download.js is a client-side JavaScript library, currently at version 1.4.7, designed to programmatically trigger file downloads within the user's browser without requiring server interaction. It provides a single `download()` function that can accept various data types, including URLs, plain strings, Blobs, Typed Arrays, and dataURLs, abstracting the complexities of browser-specific download mechanisms. The library aims to set the filename and MIME type via browser capabilities, behaving similarly to a server's `Content-Disposition` header. While the release cadence is infrequent, the library remains active, offering a lightweight solution for in-browser file generation and download. Its key differentiators lie in its broad data input flexibility and wide browser compatibility, albeit with notable limitations on older browsers and devices lacking local file system access or specific web APIs like `Blob` or `window.URL`.","status":"active","version":"1.4.7","language":"javascript","source_language":"en","source_url":"https://github.com/rndme/download","tags":["javascript","files","dataURL","blob","download"],"install":[{"cmd":"npm install downloadjs","lang":"bash","label":"npm"},{"cmd":"yarn add downloadjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add downloadjs","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The CommonJS module exports the download function directly, not an object with named exports.","wrong":"const { download } = require('downloadjs');","symbol":"download","correct":"const download = require('downloadjs');"},{"note":"Available globally when the library is included via a <script> tag.","symbol":"download","correct":"download(data, strFileName, strMimeType);"},{"note":"For use with Asynchronous Module Definition (AMD) loaders like RequireJS.","symbol":"download","correct":"require(['path/to/downloadjs'], function(download) { download(data, strFileName, strMimeType); });"}],"quickstart":{"code":"if (typeof download === 'function') {\n  console.log('download.js is available!');\n\n  // Download a plain text file\n  download('Hello, Checklist Day!', 'greeting.txt', 'text/plain');\n\n  // Download an HTML file with bold text from a Blob\n  const htmlContent = '<h1>Welcome!</h1><p>This is <b>bold</b> text.</p>';\n  download(new Blob([htmlContent]), 'welcome.html', 'text/html');\n\n  // Download a file from a data URL\n  const dataUrl = 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"><circle cx=\"50\" cy=\"50\" r=\"40\" fill=\"red\" /></svg>';\n  download(dataUrl, 'red-circle.svg', 'image/svg+xml');\n\n  console.log('Check your downloads folder for greeting.txt, welcome.html, and red-circle.svg');\n} else {\n  console.error('download.js function not found. Ensure the script is loaded.');\n}","lang":"javascript","description":"Demonstrates basic usage of the global `download` function to save various types of client-side generated files like text, HTML, and SVG."},"warnings":[{"fix":"Inform users about device limitations or provide alternative file handling mechanisms for incompatible platforms.","message":"Devices without a local filesystem (e.g., iPhone, iPad, Wii) cannot save files using this library.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware of these limitations for users on very old browsers. The library provides a best-effort approach.","message":"Older browsers or legacy devices that do not support the `a[download]` attribute will only be able to download a few hundred kilobytes of data, and may not honor the custom filename provided.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check browser compatibility for Blob API if using Blob or TypedArray inputs. Consider polyfills or fallback mechanisms for older browsers.","message":"Browser support for Blobs and TypedArrays is required to download these data types. Devices without Blob support will fail when attempting to download them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For AJAX downloads, use an explicit `XMLHttpRequest` with `responseType='blob'` and manually call `download(e.target.response, ...)` in the `onload` handler.","message":"Callback mode for AJAX operations will not work correctly with vanilla XMLHttpRequest or when dealing with binary files, as it expects specific success callback arguments.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test thoroughly on target Android devices and browsers, especially for older OS versions.","message":"Android support for the built-in browser begins at version 4.2. Chrome 36+ and Firefox 20+ on Android 2.3+ generally work well. Older Android versions may have limited or no functionality.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"This is often a fundamental device limitation. The library cannot circumvent the absence of a file system. Inform users of this limitation.","cause":"The device lacks a local filesystem or sufficient browser support to handle client-side downloads programmatically.","error":"File not downloaded on mobile (e.g., iOS)"},{"fix":"Update browser if possible, or accept that custom filenames may not be honored on very old systems. The content type should still be correct.","cause":"The user's browser is an older version or a legacy device that does not support the `download` attribute on anchor tags, which is used to suggest a filename.","error":"Downloaded file has a generic name (e.g., 'download.bin', 'unknown')"},{"fix":"Check the browser's compatibility for the Blob API. For environments lacking Blob support, you might need to convert data to a dataURL string as a fallback, although this has size limitations.","cause":"The browser in use does not have full support for the Blob API.","error":"download() called with a Blob or TypedArray argument fails"}],"ecosystem":"npm"}