DEV Community

Cover image for What Happens When You Refresh a Web Page? Understanding Browser Cache for Beginners
Darshan R
Darshan R

Posted on

What Happens When You Refresh a Web Page? Understanding Browser Cache for Beginners

Have you ever noticed that a website sometimes loads slowly the first time, but much faster when you visit it again?

For example, imagine you open an online shopping website for the first time.

The browser needs to download things like HTML, CSS, JavaScript, images, and fonts.

After the page loads, you refresh it.

Suddenly, the page may load much faster.

So what happened?

The answer is browser caching.

What Is Browser Cache?

A browser cache is temporary storage used by your browser to keep copies of certain resources from websites.

Think of it like keeping frequently used things at home instead of going to the store every time you need them.

For example, a website might contain:

style.css

app.js

logo.png

font.woff2

The browser can store some of these resources in its cache.

So when you visit the website again, the browser may be able to reuse them instead of downloading everything again.

What Happens When You Visit a Website for the First Time?

Let's say you visit example.com.

The browser requests the resources needed to display the page.

The simplified flow is:

Browser → Server → HTML, CSS, JavaScript, Images → Browser → Display Page

While receiving these resources, the browser may store some cacheable resources locally.

For example:

Browser Cache → style.css, app.js, logo.png

Now the browser has some resources available for future use.

What Happens When You Refresh?

Now you press Refresh 🔄.

The browser doesn't always download everything again.

Instead, it can check whether cached resources can still be used.

The simplified process is:

Refresh Page → Browser Checks Cache → Can Cached Resource Be Reused?

If yes, the browser may use the cached resource.

If not, it may request the resource again from the server.

This can make websites feel much faster.

Does Refresh Always Use the Cache?

Not necessarily.

The browser follows caching rules provided by the website.

The server can tell the browser how a resource should be cached using HTTP response headers.

One important header is Cache-Control.

For example:

Cache-Control: max-age=3600

This tells the browser that the resource can generally be considered fresh for a certain amount of time.

So caching isn't simply:

"If I downloaded it once, always use it."

The browser follows rules to decide whether a cached resource can be reused or needs to be checked again.

What Is ETag?

Another useful concept is ETag.

An ETag is a value that helps the browser and server determine whether a resource has changed.

Imagine the browser previously downloaded app.js.

The server provided an ETag for that version.

Later, the browser can ask the server whether that version is still current.

If the resource hasn't changed, the server can respond with:

304 Not Modified

This means the browser can continue using its cached copy.

If the resource has changed, the server can send the newer version.

The basic idea is:

Browser has cached file → Checks with server → Has it changed?

No → Use cached copy

Yes → Download the new version

What Happens When You Press Ctrl + R?

When you press Ctrl + R, you're performing a normal reload.

The browser still follows the relevant caching rules while loading the page.

It doesn't necessarily mean:

"Delete everything and download everything again."

That's an important distinction.

What About Ctrl + Shift + R?

You may have noticed another shortcut:

Ctrl + Shift + R

This is commonly used for a hard reload.

It asks the browser to reload the page while being more aggressive about bypassing cached resources.

Developers often use it when they've changed CSS or JavaScript but the browser appears to be showing an older version.

For example:

You update style.css → Refresh → Old CSS may still appear → Hard Reload → Browser fetches the latest resources

The exact behavior can vary by browser and situation, but the main idea is that a hard reload is useful when you want to avoid relying on cached resources.

Why Is Browser Caching Useful?

Caching provides several benefits.

Faster Loading

Previously cached resources may not need to be downloaded again.

Less Network Usage

The browser may reuse local resources instead of downloading them repeatedly.

Better User Experience

Pages can feel faster, especially when returning to a website.

For example:

First Visit → Download Resources → Cache Them

Second Visit → Reuse Available Resources → Page May Load Faster

But Caching Can Cause Problems Too

Imagine you're a developer.

You update your website's CSS.

Old CSS → New CSS

But a user still sees the old design.

Why?

Their browser might still have an older cached version of the CSS.

This is one reason developers sometimes use techniques such as cache busting or versioned filenames.

For example:

app.v1.js

Later:

app.v2.js

Because the filename changed, the browser treats it as a different resource and requests the new file.

A Simple Real-World Example

Imagine you visit a news website for the first time.

The browser downloads the HTML, CSS, JavaScript, images, and other resources needed to display the page.

Some of these resources may be stored in the browser cache.

Later, you refresh the page.

The browser checks its cache and the website's caching rules.

If a resource can still be reused, the browser may use the cached copy.

If a resource needs to be updated, the browser requests it again.

So the simplified flow is:

First Visit → Download Resources → Store Cacheable Resources

Refresh → Check Cache → Reuse What Can Be Reused → Fetch What Needs Updating → Display Page

That's why a page can sometimes load faster after the first visit.

The Complete Picture

So what happens when you refresh a web page?

The simplified process is:

You click Refresh → Browser starts loading the page → Browser checks cached resources → Caching rules are considered → Reusable resources may come from cache → Changed or expired resources may be requested → Server sends responses when needed → Browser combines the resources → Page is displayed

A Simple Mental Model

You don't need to memorize every caching term.

Just remember:

First visit: The browser downloads resources and may store some of them in the cache.

Refresh: The browser checks whether cached resources can still be reused.

If reusable: The browser may use the cached copy.

If outdated: The browser may request an updated version.

That's the basic idea behind browser caching.

Final Takeaway

Browser caching is one of those things we use every day without thinking about it.

When you visit a website, your browser may store resources such as CSS, JavaScript, images, and fonts.

When you return or refresh the page, the browser can reuse those resources when the caching rules allow it.

This helps websites load faster and can reduce unnecessary network requests.

The next time you press Refresh, remember:

The browser isn't necessarily starting from zero. It may already have some of the resources the page needs.

And that's the basic idea behind browser caching. 🚀


Thanks for reading!

If you're learning web development, understanding what happens behind everyday browser actions can help you build a much stronger foundation.

Top comments (0)