Static Content Hosting: Serving Files From Cloud Storage Instead of Your App
Move unchanging files like images, styles, and scripts to cloud storage behind a CDN, so your app servers handle only the work that must be built fresh.
In short
Static content hosting moves unchanging files like images, styles, and scripts to cloud storage behind a CDN, so app servers only handle work that must be built fresh.
11 min readFree
What you will learn
Every website is made of two kinds of content. Some content is built fresh for each visitor, such as a list of their orders. Other content never changes between visits, such as a logo, a stylesheet, or a script file. This lesson is about the second kind. You will learn why serving those unchanging files from your main application wastes resources, how cloud storage and a content delivery network can take that job over, and how to keep the files fresh when you change them. You will also see a worked example and learn when this pattern is a poor fit.
Key words
- Static file
- A file whose contents stay the same from one visit to the next, such as an image, a stylesheet, or a script.
- Dynamic request
- A request whose answer is built fresh each time, such as a page that shows one person's account.
- Cloud storage
- A rented service that keeps files and serves them over the web. Storage areas are often called buckets or containers.
- CDN (content delivery network)
- A network of servers spread across many places that keeps copies of files close to the people who ask for them.
- Edge server
- One server in a CDN, placed near readers. It holds the copies that readers receive.
- Origin
- The original home of a file. When a CDN has no copy, it fetches the file from the origin, here the cloud storage.
- Cache
- A saved copy of something, kept so the next request is quicker.
- Cache header
- A note sent with a file that tells browsers and CDNs how long they may keep their copy.
- Cache busting
- Making a changed file look new to caches, so they fetch it again instead of using an old copy.
- Versioned file name
- A file name that includes a fingerprint of the file's contents, such as app.3f9a1c.js.
What is the problem with app servers doing file work?
Many web applications have a simple pattern in the way they work. The app runs code to build each page, and the same app also sends out images, stylesheets, and scripts. The Azure Architecture Center describes this as a common design issue. Pages such as HTML, images, style sheets, client-side JavaScript, and PDF documents often need no processing on each request. You can build them once during a publishing step and update them on their own schedule.
A web server can deliver those files, and it is good at it. Still, each download uses the same processor time, memory, and network capacity that the server needs for the work only it can do, such as checking a login or calculating a shopping cart total. When many visitors ask for the same logo at once, the app spends effort on a job that never needed the app at all.
Why do static files waste compute?
Compute means the processing power that runs your code. Renting compute typically costs more than renting storage. If a server is busy sending the same photo again and again, you may need more servers to keep up with dynamic requests. The static content hosting pattern tries to avoid that extra spending by letting cheaper storage answer those file requests instead.
How does cloud storage take the load?
The pattern works by putting the static files into a cloud storage service. The storage service then answers each request for those files, so the app servers do not have to. Clients, meaning browsers or phones, ask for the file over HTTP, which is the standard web request method, and get the bytes straight back. The app is left to handle only the requests that need real logic.
Lower cost
Storage is usually much cheaper than compute. The saving is real only if you avoid enough compute to pay for the storage and the delivery traffic. Check both sides before you move anything.
Less load
Fewer requests reach the app. During a busy period, the servers keep their capacity for the pages that depend on live data.
Lower latency
Latency is the wait time for one request. When a CDN sits in front of storage, the file comes from a nearby server, so the wait is shorter for far-away readers.
Focused app servers
The app team can stop tuning the app for file delivery and concentrate on the logic that makes the product unique.
Tip
Storage is not free of cost. Before moving files, estimate the traffic, file sizes, and cache hit rates, then compare the result with the compute you expect to save.
How does a CDN deliver files close to users?
A CDN is usually placed in front of the storage. Its edge servers store copies of the files, so a reader in one country may get a file from a server in their own region rather than from the storage location. The CDN keeps the copies for as long as the cache headers allow. When it has no copy, it fetches one from the origin storage, saves it, and serves it. Later readers near the same edge server get the saved copy with no trip back to storage.
Edge locations and cache headers
Two settings decide how long a copy lives. The first is the edge location, which is the spot where the CDN keeps its copy near the reader. The second is the cache header that the storage sends with the file. Its Cache-Control value tells browsers and CDNs whether to store the file and for how long. A common plan gives fingerprinted assets a long lifetime, such as one year, and marks them as immutable, meaning they should not change. A year is 31,536,000 seconds. The main HTML page of the site gets a shorter rule, often a rule that says to check with the server before using the saved copy.
Set these headers when you upload the file. Also check the content type and compression values. If the headers are wrong, browsers may treat a stylesheet as plain text or cache it for the wrong length of time.
Versioned file names and cache busting
The hard part is change. If you keep the same file name and replace the contents, a browser or CDN may keep showing the old copy until its lifetime ends. Cache busting solves this. The simplest method is a versioned file name. A build tool computes a fingerprint from the file's contents and places it in the name, such as style.4b8e10.css. When the contents change, the fingerprint changes, the name changes, and every cache treats the file as new. Some CDNs ignore query strings such as ?v=2 when they decide what to cache, so a changed name is usually more reliable than a changed query. The HTML page that links to the file must then be updated to use the new name.
The code below shows a small rule that picks the cache header from the file name. It uses only the standard library and prints the same result every time.
import re
def cache_rule(name):
# A name like app.3f9a1c.js has a 6-character fingerprint before the extension.
if re.search(r"\.[0-9a-f]{6}\.(js|css)$", name):
return "public, max-age=31536000, immutable"
return "no-cache"
for name in ["app.3f9a1c.js", "index.html", "logo.png"]:
print(name, "->", cache_rule(name))
Output
app.3f9a1c.js -> public, max-age=31536000, immutable index.html -> no-cache logo.png -> no-cache
Worked example: a news article page
Imagine a news site. Each article page has a headline, a story, and related links that change often. Those parts need the app, so the app server builds the HTML. The logo, the stylesheet, the JavaScript bundle, and the article photos never change for a given release. The team puts those files in a storage bucket, places a CDN in front of it, and uses fingerprinted names. Here is how one page load works.
- 1
The app builds the page
A reader asks for an article. The app server looks up the story and writes the HTML. This is a dynamic request, so the app does the work.
- 2
The HTML names the static files
The page points to files such as app.3f9a1c.js for the script, site.5e0b71.css for the styles, logo.png for the logo, and the photo files. Each name is a versioned name.
- 3
The browser asks the CDN
The reader's browser requests each static file from the nearest edge server. The app server is not involved in these requests at all.
- 4
The first reader fills the cache
If the edge server has no copy, it fetches the file from the bucket, saves it using the cache header, and sends it on. Later readers in that region get the saved copy.
- 5
A new release goes out
The team uploads app.9c04e2.js to the bucket. The new HTML page points to that name. Readers receive the new page at once, and the new script is fetched because its name is new. The old file stays in the bucket for any cached older page that still uses it.
Tip
Notice that no one had to purge the cache for the script. The new name did the work. Purges are still useful for the HTML page, because the page name stays the same across releases.
Check your understanding
Quick check
A small shop's website slows down every time a sale starts. Monitoring shows its web servers spend most of their time sending product photos and CSS files. What change would you make, and why would it help?
When does the pattern fit, and what are the trade-offs?
The pattern suits sites where many files are the same for every visitor. It is less useful when the app must change each file for each user, or when the site has very few files, because the extra step may cost more than it saves. Below are the main design choices to think through before you start.
Public or private content
Public files can be read by anyone. Private files, such as invoices, need a login check. Public files can sit in a bucket that only the CDN may read. Private files need their own protection, and a shared CDN cache can expose them if it is set up wrongly.
HTTPS and addresses
Use HTTPS, the encrypted form of HTTP, by default. Decide whether static files use your site's own address or a separate hostname. A separate hostname can affect search results, because search engines may treat it as a different site.
Separate deployment
Static files can be released apart from the app code. This is useful, but it means two release paths must stay in step. Upload new files before the pages that link to them, and keep old files until no cached page or old app version still needs them.
Failure risk
The CDN and the storage become parts you depend on. If the CDN has no copy during an outage at the origin, readers may see missing files, so plan how to handle that.
Fully static sites
Some sites contain only static files. A single-page app, which is a site that loads one page of code and updates it in the browser, is an example. A static site generator is a build tool that turns content files into finished HTML pages ahead of time. Both can be hosted entirely in a storage account behind a CDN, with no application server at all. The Azure guidance notes that this might be possible, depending on the capabilities of the hosting provider's storage system.
Tip
Keep the HTML page on a short cache rule and the fingerprinted files on a long one. Mixing the two up is the most common cause of stale pages.
A second check
Quick check
A team edits style.css in place and keeps the same file name. Days later, some readers still see the old colours. Which change fixes this for future releases?
Key takeaways
Static content hosting moves files that never change for each visitor into cloud storage, usually behind a CDN. The app servers then keep their capacity for dynamic work. Cache headers tell browsers and CDNs how long to keep copies. Versioned file names let you release changes at once, because every new file has a new address. Check the cost, the privacy of each file, and how the pieces are deployed before you adopt the pattern. For related ideas, look at how caching and CDN delivery work in the other lessons of this course.
Tip
When you design a site, list every file the page needs and label each one as static or dynamic. The static list is your first candidate for storage and a CDN.
Sources
- Static Content Hosting pattern, Azure Architecture Center (Microsoft Learn)
- CDN guidance, Azure Architecture Center (Microsoft Learn)
- CDN JavaScript Best Practices: Versioning and Cache Busting (BlazingCDN blog)
- Cache Busting Strategies with CDNs and Browser Caching (dchost blog)
- CDN Cache Busting for Beginners: Practical Techniques to Ensure Fresh Content (USAVPS blog)
- How to Serve Static Assets With an Efficient Cache Policy (NitroPack blog)
Last updated on 18 November 2026
Related lessons
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.