Open In App

Disable Browser Caching with Meta HTML Tags

Last Updated : 08 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In the fast-paced internet era, delivering up-to-date content to users is crucial. Browser caching, while speeding up website loading, poses challenges in serving recent updates. Fortunately, developers can leverage meta HTML tags to control caching behaviour, ensuring users receive the latest content promptly. This article explores the significance of browser caching and demonstrates the use of meta HTML tags to enhance web speed.

Using the Cache-Control Meta Tag

The browser cache should not be used and when you load the page or refresh it, the content should be served from the server, not from the cache.

Example: To demonstrate using the “Cache-Control” Meta Tag to disable browser facing with the meta HTML tags.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Cache-Control" content="no-cache">
    <title>Disable Browser Caching</title>
</head>

<body>
    <h1>Hello World!</h1>
    <p>This page should not be cached by the browser.</p>
</body>

</html>

Output:

1ezgif-3-5c976b4493

Disable browser caching Using Cache-Control Meta Tag

This output is unlike the common feed of traditional programming output in the sense that it cannot be seen in reality. There instead, the output though is seen in the actions of the browser’s caching mechanism when you visit the page.

Using the Pragma Meta Tag

This is similar to the cache control meta tag having a no-cache attribute which makes the browser not cache the page. Hence the content is fetched afresh from the server when one visits a page or refreshes the same.

Example: To demonstrate using the “Pragma” Meta Tag to disbale browser caching with meta HTML tags.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <title>Disable Browser Caching</title>
</head>

<body>
    <h1>Hello World!</h1>
    <p>This page should not be cached by the browser.</p>
</body>

</html>

Output:

1ezgif-3-5c976b4493

Disable browser caching Using Pragma Meta Tag

This output is unlike the common feed of traditional programming output in the sense that it cannot be seen in reality. There instead, the output though is seen in the actions of the browser’s caching mechanism when you visit the page.

Using the Expires” Meta Tag

Through the use of the expiration ate in the past, the browser should regard the file as expired and not cache it. Accordingly, the content has to be downloaded each time the page is loaded or refreshed.

Example: To demonsrtate using the “Expires” Meta Tag to disable browser caching with the meta HTML tags.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT">
    <title>Disable Browser Caching</title>
</head>

<body>
    <h1>Hello World!</h1>
    <p>This page should not be cached by the browser.</p>
</body>

</html>

Output:

1ezgif-3-5c976b4493

Disable browser caching Using Expires Meta Tag

This output is unlike the common feed of traditional programming output in the sense that it cannot be seen in reality. There instead, the output though is seen in the actions of the browser’s caching mechanism when you visit the page.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads