Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6815815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:51:07+00:00 2026-05-26T20:51:07+00:00

PROBLEM: I am hosting a widget on a client’s website that will be different

  • 0

PROBLEM:

I am hosting a widget on a client’s website that will be different for each page on the site.

To render the widget, the client includes a script tag on their pages. This script tag is loaded for every page on the site and the code that it returns depends on the page.

So, if this script gets cached, the end result is that we serve a widget for the wrong page.

Right now, when we serve the script, we set in the response headers

Cache-Control: max-age=0
Expires : 24 hours in the past

yet sometimes browsers still cache the script.

QUESTION:

Is there a way to use http headers to stop caching in all cases or are we going to have to take a completely different approach?

UPDATE:

The headers that topek recommended greatly improved the non-cacheability of the scripts. However, (again in Chrome who seems to be the most cache-aggressive) when using the back, forward, or reload buttons the script is still cached. If you actually CLICK on anything it will be fetched from the server.

It seems that the only foolproof way to stop caching will be to set script sources that are guaranteed to be different for each page load (as suggested by esilija and tejs).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:51:08+00:00Added an answer on May 26, 2026 at 8:51 pm

    Those two headers should do the trick:

    response.setHeader("Cache-Control", "no-cache, must-revalidate");
    response.setHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");
    

    or you set name according to the current page, e.g. when the user requests the page http://domain/posts/1 then the script name could be http://domain/script/scriptname/posts/1. With approach the script would still be cachable per page.

    Do not append a query string on the script like script.js?random_string. Proxies don’t play well with this approach. If you want to place a random string in the name, then put it before .js like this script-0934234234.js and rewrite the request on your server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have two spreadsheets that each serve different purposes but contain one particular
I have asp.net mvc 3 site deployed on shared hosting. My problem is that
I am trying to design a file hosting website template, the problem is i
I have a problem with a oneway web method that open a moss site
Here the problem. I have my site hosted on a shared hosting for asp.net
The Problem I have a WCF webservice that I am hosting as a webservice
I've got a problem here. I've got an ASP.net website hosting a silverlight 2
I have installed django-cms in my hosting. But there is a problem. That's when
I have recently bought VPS hosting and I assume, that it has problem with
I have been hosting a site on Heroku for a few months that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.