User Agents

Single File Sites vs Self-Hosted Assets: Privacy & Performance

Single-file websites (all HTML, CSS, and JavaScript in one .html file) and self-hosted assets (separate files on your own server) both have trade-offs. For privacy, self-hosted assets are generally better because they avoid third-party requests, while single-file sites can be better for performance in low-bandwidth scenarios. This article compares both approaches to help you choose based on your priorities.

Background: What Are Single-File and Self-Hosted Sites?

A single-file website is a self-contained HTML document that includes all CSS and JavaScript inline (via <style> and <script> tags) or as data URIs. It’s often used for offline tools, email signatures, or simple landing pages. In contrast, a self-hosted site stores CSS and JavaScript as separate files on the same server, referenced by <link> and <script src> tags. Most websites use the latter approach.

How Each Approach Works

Single-file: The browser downloads one file. All styles and scripts are embedded, so there are no additional HTTP requests. This reduces latency and works even offline if the file is saved locally. However, the file size can be large, and the browser must parse everything at once, which may delay rendering.

Self-hosted: The browser downloads the HTML first, then fetches CSS and JS files in parallel. This allows caching: once the CSS/JS are cached, subsequent page loads are faster. But each request adds latency, and if the server is slow, the page may appear unstyled or non-interactive until assets arrive.

Performance Comparison

Performance depends on context:

  • Single-file: Best for one-off loads, low bandwidth, or offline use. Example: a small tool (under 100 KB) loads in one request, avoiding round-trip delays. But if the file is large (e.g., 1 MB), it blocks rendering and cannot be cached separately.
  • Self-hosted: Better for repeat visits. Browsers cache CSS/JS, so after the first load, only the HTML (often small) is fetched. This reduces total transfer size over time. However, each uncached asset adds a round-trip, which can be slow on high-latency connections.

For a simple page with minimal assets, single-file can be faster. For a complex site with many pages, self-hosted assets win because caching benefits multiply.

Privacy Implications

Privacy concerns center on where requests go. A single-file site makes no external requests (unless it includes remote resources), so it doesn’t leak the user’s IP to third parties. Self-hosted assets also stay on your server, so they don’t leak to third parties either—provided you don’t use CDNs or external fonts/scripts. The key difference is that self-hosted assets still expose the user’s IP to your server, which is expected. Single-file sites can be opened locally (e.g., from a USB drive) with zero network requests, offering maximum privacy.

However, if you self-host assets but include third-party trackers or fonts, privacy suffers. The method itself isn’t the issue; it’s what you embed.

How to Choose: Single-File vs Self-Hosted

  • Choose single-file if: you need offline functionality, want to share a tool as a single downloadable file, or have a very small page (under 50 KB) with no repeat visitors.
  • Choose self-hosted if: you have multiple pages, expect repeat visits, or have large CSS/JS that benefits from caching. Also choose self-hosted if you need to update assets without rewriting the entire HTML.

For privacy, both are fine as long as you avoid third-party resources. For performance, test with your actual audience—use browser DevTools to compare load times.

Common Problems and Misconceptions

Myth: Single-file is always faster. Not true—large inline assets block rendering, and caching is impossible. Myth: Self-hosted is always more private. If you self-host but use a CDN, you leak IPs to the CDN. Problem: Single-file sites are hard to maintain. Any change requires editing the whole file, which is error-prone. Problem: Self-hosted can break if paths are wrong. A missing CSS file makes the page unstyled. Also, some browsers limit inline script sizes, so very large single-file sites may fail.

Costs and Maintenance

Single-file sites have zero additional cost—just one file. Self-hosted requires server storage and bandwidth, but these are negligible for small sites. Maintenance: single-file is simpler to deploy (just upload one file), but harder to update. Self-hosted allows you to update a CSS file once and affect all pages. For teams, self-hosted is more practical.

Alternatives and Hybrid Approaches

You can combine both: inline critical CSS for first paint, then lazy-load the rest. Or use a service worker to cache self-hosted assets for offline use, giving you the best of both. Another option is a CDN, but that trades privacy for performance—weigh the trade-off.

Frequently Asked Questions

Does a single-file site work offline?

Yes, if you save the file locally and open it in a browser, it works without internet—provided it doesn’t reference external resources. This is great for privacy.

Can I cache a single-file site?

Browsers can cache the whole file, but any change requires re-downloading the entire file. There’s no granular caching of CSS/JS separately.

Which is better for SEO?

Both can be indexed equally. Single-file sites may have slower rendering if large, which can affect Core Web Vitals. Self-hosted assets with proper caching often score better.

Does self-hosting assets slow down my site?

Only on the first load when assets are uncached. Subsequent loads are faster because of caching. Use HTTP/2 to multiplex requests and reduce latency.

Are there security risks with single-file sites?

If the file is downloaded from an untrusted source, it can contain malicious scripts. Self-hosted sites are generally safer because you control the server, but both require secure coding practices.

Can I use a CDN with self-hosted assets and still be private?

No, a CDN sees the user’s IP, so it’s not fully private. If privacy is critical, avoid CDNs and serve everything from your own server.