Firefox Cache outside $HOME

April 2013


Our users have their homedirs on an NFS server. Firefox is slower than it should be because its cache is on NFS.

This can be fixed by putting in /usr/lib/firefox/defaults/pref/all-MyCompany.js:

// works:

pref("general.config.obscure_value", 0);
pref("general.config.filename", "MyCompany.cfg");
    

... and in /usr/lib/firefox/MyCompany.cfg:


var env_user = getenv("USERNAME");

var env_home = getenv("HOME");
var env_mozdebug= getenv("MOZILLA_DEBUG");

// find the path to the profile directory
var profhome = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD",Components.interfaces.nsIFile).path;

// work out the profile salt+name
var profname=profhome.match(/[^\/]+$/);

// this matches what our hack wrapper symlinked the Cache into...
var cache_dir = "/tmp/MozillaFirefox-" + env_user + profname;
defaultPref('browser.cache.disk.parent_directory', cache_dir);
defaultPref('browser.cache.offline.parent_directory', cache_dir);

if (env_mozdebug) {
    displayError("debug ffox cfg v100",
                 "\n\nuser=" + env_user +
                 "\nhome=" + env_home +
                 "\n\nprofile-path="+profhome +
                 "\nprofile-name="+profname
                );
}
    

[Note]Note

The ratio between correct and outdated, beside-the-point, or just plain wrong information I could google up on this topic was particularly poor.