Explainstuff.mebeta
All concepts
Cloud Native Patternsintermediate6 min

Static Content Hosting

Stop making your app servers hand out images and scripts — serve static files from storage and a CDN instead.

Every web page is really two things mixed together. Some of it is unique to you right now — your shopping cart, your feed, your account balance. The rest is the same for everyone: the logo, the stylesheet, the product photos, the JavaScript bundle. Yet many apps make the same hardworking server compute the personalized part and hand out the identical files, over and over, to every visitor.

Static content hosting separates those two jobs. The unchanging files get served from somewhere cheap, fast, and built for exactly that — leaving your application servers free to do the work only they can do.

The problem

When your application server delivers a 2 MB hero image, it burns CPU, memory, and bandwidth doing something trivial — pushing the same bytes it pushed a thousand times before. That's capacity stolen from the requests that actually need application logic. Worse, every user pulls those bytes all the way from your origin, even if they're on the other side of the planet, so the page feels sluggish far from your data center.

You can throw more servers behind a load balancer, but that's an expensive way to solve what is, at heart, a file-serving problem. Application servers are the wrong tool for handing out files that never change.

Without static hosting — the app server hands out the files
app serves the bytes itself
Distant user
Distant user
App server
Big static files
Every visitor pulls big, unchanging files through the application server itself, wasting CPU and bandwidth on a file-serving job and slowing the dynamic work only the server can do.

How it works

You upload static assets to a cloud object store — a service designed to hold and serve files cheaply and reliably. Then you put a CDN (content delivery network) in front of it. The CDN is a global mesh of edge servers that keep cached copies of your files close to where users are, applying caching at the network edge.

Now the split is clean: a request for the page's dynamic shell goes to your application server, while requests for images, scripts, and styles go to the CDN, which serves them from the nearest edge — often without ever touching your origin. Your app servers only do dynamic work; the heavy lifting of file delivery happens elsewhere. The diagram below shows a client pulling static files from the CDN and dynamic responses from the app server.

Static Content Hosting — static from the edge, dynamic from the app
static vs dynamic
Browser
CDN edge cache
Object storage
App server (dynamic)
The browser pulls images, scripts, and styles from the nearby CDN (backed by object storage) and only hits the application server for the personalized, dynamic parts of the page.
Tip

Cache invalidation is the hard part. A CDN's whole value is holding onto copies, which means a changed file can keep serving its old version for as long as its TTL allows. The standard fix is fingerprinting: bake a content hash into the filename (app.9f3c2.js) so a new version gets a brand-new URL. Old URLs can cache forever; new deploys simply reference new ones.

When to use it

This is close to a default for any public web app or single-page application. The moment you're serving images, fonts, stylesheets, client-side bundles, or downloadable files, moving them to storage plus a CDN cuts load on your servers and slashes latency for distant users — usually for less money than running extra app capacity.

Where it fits less neatly is content that's genuinely per-user or needs strict access control on every fetch. You can serve private assets through a CDN with signed URLs, but if nearly everything is dynamic and personalized, the static-hosting win is small. The sweet spot is the large, shared, rarely-changing files that every visitor needs.

Key takeaways

  • Static assets — images, CSS, JS, videos — don't change per request, so they shouldn't be served by your application code.
  • Put them in cheap object storage and front them with a CDN that caches copies close to users.
  • This frees app servers to handle only the dynamic work they're actually needed for.
  • Users get assets from a nearby edge location, so pages feel dramatically faster worldwide.
  • The catch is cache invalidation: when an asset changes, you must make sure stale copies don't linger.

Keep going