Reduce Repeated HTML Traffic with IndexedDB
Web developers can lower bandwidth usage by caching the main HTML file in IndexedDB. The technique uses a lightweight loader page that restores the full site from the browser’s local database on repeat visits. It works best for single‑page sites with large HTML payloads.
When a website advertises itself as lightweight, the expectation is that users will experience fast load times and minimal data usage. However, if visitors repeatedly open the same HTML page, the browser’s cache may not always serve the content as efficiently as possible. In such cases, the actual amount of data transferred can exceed what developers anticipate, especially when the page includes a sizable HTML document.
Why the Browser Cache Isn’t Enough
The browser cache is a powerful tool, but it operates largely outside the control of the website. Cache headers, expiration policies, and user settings all influence whether a page is reloaded from the network or served from local storage. When a site’s HTML file is large, even a single reload can consume a noticeable amount of bandwidth, which can be problematic for users on limited data plans or slow connections.
IndexedDB: A Site‑Controlled Alternative
IndexedDB is a client‑side database that allows web applications to store structured data locally. Unlike the cache, a site can explicitly decide what to store, when to update it, and how long to keep it. By saving the main HTML document to IndexedDB on the first visit, a site can serve the entire page from the browser on subsequent visits, bypassing the need to download the full HTML again.
The approach involves two files:
- index.html – a lightweight loader that checks IndexedDB for the stored HTML.
- indexBody.html – the full HTML content that is fetched only on the first visit.
The flow is straightforward:
- Open
index.html. - The script checks IndexedDB for a stored copy.
- If found, the script injects the HTML into the page and finishes.
- If not found, the script redirects to
indexBody.html. - After loading
indexBody.html, the script saves the document to IndexedDB and then navigates back toindex.html.
Implementing the Technique
To make this system easier to adopt, a simple tool is available that converts a standard HTML file into the two‑file format required. Users can drag and drop their original file, specify a desired name, and download a ZIP archive containing the two generated files. The tool ensures that the filenames match the pattern expected by the loader script.
Once the files are hosted on the same domain, the loader will automatically handle the storage and retrieval process. Because IndexedDB is scoped to the origin, keeping the files on the same domain avoids cross‑origin complications.
When This Strategy Works Best
Not every website will benefit equally from this method. It is most effective for:
- Single‑page applications or sites that are essentially one large HTML document.
- Pages with a substantial HTML payload that would otherwise be downloaded on every visit.
- Use cases where the same page is accessed repeatedly by the same user, such as dashboards or content‑heavy portals.
External resources—images, CSS, JavaScript, fonts—are still fetched normally on each visit. Therefore, the technique primarily saves the transfer of the HTML body itself, not the entire page stack.
Comparison to Service Workers
Service Workers can also intercept network requests and provide cached responses. However, they require more setup and can be overkill for simple HTML caching. IndexedDB offers a lightweight, script‑based alternative that is easier to integrate into existing sites without the overhead of a full caching strategy.
Next Steps for Developers
To adopt this method, developers should:
- Evaluate the size of their main HTML document and the frequency of repeat visits.
- Use the provided tool to generate the two required files.
- Test the loader on various browsers to ensure compatibility with IndexedDB support.
- Consider combining the approach with other optimization techniques, such as minifying CSS and JavaScript, to maximize overall bandwidth savings.
By implementing IndexedDB caching, sites can deliver a faster, more efficient experience for users who revisit frequently, while still benefiting from the traditional browser cache for other assets.
Why it matters
Reducing repeated HTML downloads directly lowers data usage for users and speeds up page load times, which can improve engagement and reduce server load.
Key points
- IndexedDB lets sites control what data is stored locally
- A lightweight loader page restores the full HTML from the database
- The technique is ideal for single‑page sites with large HTML
- External assets still load normally, so combine with other optimizations
- Service Workers are more complex; IndexedDB is simpler for this use case
Frequently asked questions
Does IndexedDB work on all browsers?
Most modern browsers support IndexedDB, but older versions may lack full support. Test on target browsers before deployment.
Will this affect SEO?
Since the full HTML is still delivered to search engines, SEO is not negatively impacted. The loader page is lightweight and does not interfere with crawlers.
Can I use this with HTTPS only?
Yes, IndexedDB works with both HTTP and HTTPS, but it is recommended to use HTTPS for security and performance.

.jpeg?width=1200&auto=webp&quality=75)


