Firefox, the second most popular web browser, the default pre installed browser in many GNU/Linux distributions. It is really great in terms of it's customization capability and large collection of add-ons.
Though many users find firefox frustratingly slow and sluggish, so they switch to other browsers like Google Chrome or Chromium etc. There are many reasons for it's sluggish performance, like storing cache to disk, using slow sqlite databases, frequent disk access by other processes, no DNS cache and like so many of them.
But there are many of ways to make it faster and improve page load time. In this tutorial we are going to do this by modifying the firefox about:config configurations, moving all profile data to a tmpfs partition on RAM and moving the cache to RAM instead of hard disk. This guide will work all GNU/Linux Distributions like Ubuntu, Fedora, Debian, Arch Linux etc. etc.
Optimize the about:config configurations
Open up firefox, type about:config in the URL bar , hit Enter and press the I’ll be careful, I promise! button, now you can edit the configurations. Use the search bar to find configurations easily.
- Search for browser.cache.use_new_backend , if the value is 0 , modify it to 1 , this makes the caching efficient.
- Search for network.http.pipelining.ssl toggle it value to true .
- Search for network.http.pipelining , toggle the value to true .
- Search for network.http.proxy.pipelining , toggle its value to true .
- Search for network.http.pipelining.maxrequests , modify the value , set any thing above 100 , like 120 .
- If you are not using IPv6, then search for network.dns.disableIPv6 and toggle its value to true .
- Search for browser.safebrowsing.enabled and browser.safebrowsing.malware.enabled , toggle the value to false, in both of them, though this is a little bit dangerous.
Move the cache to RAM
As RAM is much much more faster than hard disk, so moving cache to RAM will increase the user experience greatly. Recent computers have plenty of free RAM, so moving the cache to RAM will not be a problem. But avoid this if you have less than 1 GB RAM.
- Again, open up firefox and type about:config in the URL bar, hit Enter and press the I’ll be careful, I promise! button. Now edit few thing in this section.
- Search for browser.cache.disk.enable in the filter bar, toggle the value to false , this will disable cache to disk.
- Now it is the time to enable cache to RAM, search for browser.cache.memory.enable , if the value is true leave it else toggle it to true.Now assign how much memory could be used as RAM cache, search for browser.cache.memory.capacity , if not found create it.Right click on blank area, then select "New" > "Integer" , set the preference name browser.cache.memory.capacity , enter the integer value in KB, like 204800 for 200 MB , and done . Check it with about:cache .
Move profile data to a tmpfs partition
Finally move all profile data to a tmpfs partition on RAM , tmpfs is a incredibly fast special type of file system that uses a part of RAM to store data. Firefox stores almost every information in SQLite databases, but SQLite is inherently slow and disk I/O dependent. This process will make Firefox blazing fast and disk I/O independent.
1. clear all cache and cookies
Perhaps you know how to do that, if not, click Edit > Preferances go to Privacy and clear cookies, then go to Advanced > Network clear Cached Web Content and done !
2. backup default profile data
Create a backup archive of your current data, before doing this close Firefox and look at the commands bellow.
cd .mozilla/firefox/ cp -a profile_name.default/ profile.bac rm -rf profile_name.default/*
must replace profile folder name with your own profile folder name. This will create a folder named profile.bac containing all profile data and clear all data inside the default profile folder.
3. mount the tmpfs on profile folder
Add the line bellow to the
tmpfs /home/$USER/.mozilla/firefox/profile_name.default tmpfs size=128M,user,exec,uid=1000,gid=1000 0 0
My firefox default profile name was p3iyxcse.default , so the line at
/etc/fstab looks like bellow.
tmpfs /home/b00m/.mozilla/firefox/p3iyxcse.default tmpfs size=128M,user,exec,uid=1000,gid=1000 0 0
Make sure that the
/home/$USER/.mozilla/firefox/profile_name.default directory exists, otherwise tmpfs mounting will fail .
Now mount the tmpfs at profile directory , i.e. at
/home/$USER/.mozilla/firefox/profile_name.default and copy all the backup data to the default profile folder.
sudo mount -a cd .mozilla/firefox/ cp -a profile.bac/* profile_name.default/
Do not forget to replace profile_name.default with your own profile name. And now start Firefox, if you have a slow HDD like me, then you will notice a much faster start up time and no sluggish performance .
4. sync any changes to the profile folder with the backup folder
In order to keep the changes intact after a reboot or shutdown, we need to sync the profile folder with the backup folder time to time.
To do this without any user interaction in later, save the script bellow as ff_profile_sync and add it to crontab . Before doing this if you do not have rsync , run
sudo apt-get install rsync on Ubuntu, Debian or Linux Mint etc. the script is below.
#!/bin/sh cd /home/$USER/.mozilla/firefox/ if test -d *.default;then if test -d profile.bac;then rsync -a --delete *.default/ profile.bac/ fi;fi
Do not forget to replace $USER with your username, save this script at
/usr/local/bin or wherever you like, make it executable, and add to crontab with
crontab -e , set the cron interval 5-10 minute or whatever you like.
Put the line bellow for a 5 minuite update interval .
*/5 * * * * /usr/local/bin/ff_profile_sync > /dev/null 2>&1
Finally add the line bellow to the
/etc/rc.local file just before the exit 0 , to restore the previous changes after a reboot .
cp -a /home/$USER/.mozilla/firefox/profile.bac/* /home/$USER/.mozilla/firefox/profile_name.default/
Again, Do not forget to replace $USER with your username and profile_name with your firefox profile name.
This setup will backup all changed profle data to the profile.bac folder automatically, so forgot about it , and enjoy super fast firefox.
If you have any question or need further assistance just leave a comment, we’d be happy to assist you.
Also feel free to share this tutorial with your friends.
thanks ! nice how to.
Julius Thijssen says
Just so you know, I've been using Anything Sync Daemon (works fine in debian and ubuntu too: https://github.com/graysky2/anything-sync-daemon ), this is a great ram-disk usage script, mitigating all the problems mentioned here with maintaining a steady-state ff profile despite reboots, crashes etc.
Arnab Satapathi says
Thanks Julius for mentioning the script, much appreciated.
Thanks, however, my firefox(56.0) keeps using ~/.cache/mozilla/firefox/XXX.user/ directory. I took your ideas and create 2nd tmpfs for it, now my hard drive truly stays quiet while i'm using firefox, and feel a lot faster.
and I put the script in .bash_logout to update cache to bac folder in disk.
what if the folder /home/$USER/.mozilla/firefox/profile_name.default does not exist?
I'm operating in a fresh installation of Linux Mint 18 and I can't find it, even when displaying hidden items...
Thanks for you advice,
Arnab Satapathi says
Run firefox for once, the profile folder will be created.
Mine exists but mount -a refuses to mount claiming:
root@HelloMotto:~/.mozilla/firefox# mount -a
mount: mount point /home/$USER/.mozilla/firefox/bfyxu7lk.default does not exist
bfyxu7lk.default Crash Reports profile.bac profiles.ini
Arnab Satapathi says
Are you sure you're using all paths correctly?
Typing commands as root@HelloMotto:~/.mozilla/firefox# While using the fstab entry as /home/$USER
Hi Thanks for the response,
what do you mean by typing as root@HelloMotto:~/.mozilla/firefox#
as being in that location while typing mount -a?
and should my entry in fstab be
total linux noob,
thanks in advance
OK I've managed to use the right path, in fstab it had to be
Now I'm stuck at rc.local which doesn't exist on my linux, instead i have:
Arnab Satapathi says
rc.local file is now obsolete with systemd, but if there's no rc.local file, then create it, and make it executable with
Also don't forget to add the exit 0 line at the end of file. It will be automatically called by systemd after next reboot.
However why you're using linux as root? I presume you're using Kali linux.
OK I think all worked, it is definitely quicker.
Just wondering if the fact that in about:cache there's no location for storage disk location as per the below
"Storage disk location: none, only stored in memory"
would be a good indicator of browser using RAM(assuming other things have been set correctly)?
Yes it kali
Thanks for you help 🙂
Great work but one remark : you don't have to do a cronjob for new data being kept after a reboot, shutdown or even a crash (especially dealing with rc.local isn't the most proper way to do the job but rather a workaround).
Instead of doing a cronjob through an rsync script, you can just write a --bind mount in fstab just after the previous one where you mounted firefox profile folder on tmpfs... The line would look like this :
/home/$USER/.mozilla/firefox/profile.bac /home/$USER/.mozilla/firefox/profile_name.default none bind
Arnab Satapathi says
Thanks ! Very good tip, I'll try it and update the tutorial.
Well I withdraw what I said about binding folders, after some tests it doesn't behave as expected... The two mounts are still there but the second when binding folders overwrites all specs of tmpfs mount... So it wasn't a good tip at last 🙁 My bad.
Arnab Satapathi says
Awe, It was a great idea, but sadly refused to work properly.
This is an excellent idea! Is there a way of checking that the profile was successfully mounted to tmpfs? And a way of checking it's synching properly?
Hi Pablo, good questions 🙂
1. If the machine was shutdown, perhaps there is no way to check if the profile folder was mounted as tmpfs or not, unless you run some script to monitor that activity. But you can easily check if the folder is currently mounted by the mount command.
2. You can check if the profile folder was synced properly or not by monitoring the crond logs, use this
grep -i 'cron' /var/log/syslog
1. It says tmpfs on /home/pablo/.mozilla/firefox/blahblah.default type tmpfs (rw,nosuid,nodev,size=128M,uid=1000,gid=1000). Is that alright?
2. Yes, it's working!
Yeah Pablo, it's alright.
And what abour adding a line to /etc/rc6.d to make it sync at shutdown or reboot?
Hi, almost works fine, except my when I want to copy my default.profile shows me a lot error messages :
#cp -a k02hcabe.default.back k02hcabe.default
I got these messages:
cp: no se puede crear el fichero regular «k02hcabe.default/k02hcabe.default.back/sessions/backup-70.session»: Permiso denegado
What's the language ? Spanish ? It seems like that you don't have proper permission to create the folders/files.
Try this cp -a k02hcabe.default k02hcabe.default.back
And thanks for your feedback.
mad slackw says
i'm experiencing some trouble with your tutorial regarding the backup of default profile data
if you say :
cp -a profile_name.default/ profile.bac
and after that
rm -rf profile_name.default/*
what happens is that the profile_name.default is removed, right ? so when i try to mount the profile_name_default i see the message :
/home/$USER/.mozilla/firefox/3x9htqj8.default does not exist
and the subsequent steps fails, so right now i have a kind of a new firefox install everytime i reboot the laptop
am i doing something wrong on this steps ?
thanks in advance
Does the folder 3x9htqj8.default exists ?
I tested the procedure again just before writing this comment, and it's working with Firefox 45 .
You may try to temporarily mount the profile folder, for testing purpose,
sudo mount tmpfs -t tmpfs -o size=128M /home/$USER/.mozilla/firefox/3x9htqj8.default
Hope this helps, and please don't forget to notify me when you're done.
I followed your guide and there's definitely some improvement. Thank you!
One question: Will the tmpfs changes hold with Firefox updates? Do I need to do this again after the next update?
Thanks Sajesh for comment !
You don't need to worry about firefox update, all changes are hold on disk, inside the ~/.mozilla/firefox/profile.bac/ folder.
Thank u so much for sharing this tricky job...very helpful
Thanks Siddhartha, I hope now your firefox is running blazing fast !! Stay connected with us.