Avoid Unwanted Browser Caching Using JavaScript

Sometimes, you’ll notice that when you open a URL (with dynamic content, and especially a pop-up window) a second time, the page displays the data which was displayed earlier and not the data newly expected. One example of this is when you open a pop-up window that shows exported data in Excel. This happens because browser has cached the earlier URL response and is displaying it (even if the content has changed in next request-response cycle). This tip addresses this problem.

What is “browser cache”? The browser has a folder in which certain items that have been downloaded are stored for future access. Graphic images (such as buttons, banners, icons, advertising, graphs, and color bars), photographs, and even entire web pages are examples of cache items. While accessing a web site, your computer will check its cache folder first to see if it already has the contents needed to display the page and, if so, it won’t take the time to download them again. This makes for faster page loading.

Sometimes, the browser caches complete pages that have been visited and displays them in response to the same URL when visited again. The browser feels that it is helping us (and caching does help, but not in this situation).

The simplest way to solve this is to change the URL every time you visit. This can be done by adding a dummy request parameter (like the time) to the URL whose value changes every time you visit the page.

Suppose you have the URL:

window.open (http:\localhost:8080/Web/calcuateInterest.jsp,,)

Change it to this URL :

window.open (http:\localhost:8080/Web/calcuateInterest.jsp?dummyParameter=new Date().getTime(),,);

This URL actually appends the time in milliseconds as the request parameter. This changes the URL on each hit unless you manage to hit same URL in same millisecond.

Note: The JavaScript method getTime() of the Date object gives time elapsed in milliseconds.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.