Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One of the companies I work with has a web app hosted over a slow DSL line. There is something amiss with the configuration of their server or version of software they are using which means that every page access is triggering a download of a huge collection of JavaScript libraries. According to Firebug the actual contents of each page is delivered relatively quickly so.

Is there a way to force Firefox to consider a particular URL to have a longish expiry period?

Many years ago I used to do this sort of thing on squid proxy installs with custom regex rules to force a minimum cache age for misbehaving sites. What I'm trying to do seems similar but purely client side.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Manipulating a particular cache entry isn't really possible, not even Firefox extensions have that level of access. It is possible to manipulate the headers that the server returns however. Unfortunately, all the existing extensions focus on manipulating the request headers rather than response headers. But an extension for that would be really simple. So maybe you want to try that route before you install Squid again. Here is the code for an extension like that:

install.rdf

<?xml version="1.0" encoding="utf-8"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>headermanip@superuser.com</em:id>
    <em:version>1.0</em:version>
    <em:type>2</em:type>
    <em:bootstrap>true</em:bootstrap>

    <!-- Firefox -->
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>8.0</em:minVersion>
        <em:maxVersion>99.0</em:maxVersion>
      </Description>
    </em:targetApplication>

    <!-- Front End MetaData -->
    <em:name>Caching header manipulation</em:name>
  </Description>
</RDF>

bootstrap.js

Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function install(data, reason) {}
function uninstall(data, reason) {}

function startup(data, reason)
{
  Services.obs.addObserver(Observer, "http-on-examine-response", true)
};

function shutdown(data, reason)
{
  Services.obs.removeObserver(Observer, "http-on-examine-response")
};

var Observer =
{
  observe: function(subject, topic, data)
  {
    if (subject instanceof Components.interfaces.nsIHttpChannel &&
        subject.URI.host == "cdn.sstatic.net")
    {
      subject.setResponseHeader("Cache-Control", "max-age=2592000", false);
    }
  },

  QueryInterface: XPCOMUtils.generateQI([
    Components.interfaces.nsIObserver,
    Components.interfaces.nsISupportsWeakReference
  ])
};

Put these two files into a ZIP archive and rename it into headermanip.xpi - done, you have an extension that will change the caching header for anything coming from cdn.sstatic.net (used on this site) to expire after 30 days rather than the usual 7 days. If you want it to happen on a different host - change the subject.URI check in bootstrap.js. You can also check subject.URI.spec if you want to look at the full URL rather than the host only.

share|improve this answer
add comment

The BetterCache addon looks promising, but its whitelist and blacklist seem to work on MIME types only, not URLs, and according to a review text/javascript should be blacklisted for some captchas to work properly.


I don't think there's a built in way to do this.

...
...

And this is where someone proves me wrong.


You could always install squid locally (on the same computer), that's technically client side...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.