Storing a Last-Modified Date in a Cookie

Storing a Last-Modified Date in a Cookie

On informational Web sites, it is often handy to be able to show certain kinds of information only once, and then keep it hidden until it is updated. That way, users don’t have to look at the same message every time they come to the site. You can do this by setting a cookie with a version number and an expiration date. Cookies can be set in a variety of ways; one of the easiest is with JavaScript. To set a cookie that records the date a document was modified on, use the following code:


This code will store the last modified date in a cookie on the user’s machine, and you can refer to it as needed.


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist