User avatar
Posts: 137
Joined: Fri Jun 12, 2015 12:15 am

HOW TO: improve browser experience

Thu Feb 09, 2017 7:05 am

If you want Flash in FireFox try the following post:
HOW TO: pepperflash in FireFox 2017

0. Get rid of ads, they will save you bandwidth

Replacing your /etc/hosts file will save you A LOT of bandwidth, especially if you have a flash plugin installed. The best on the net is MVPS HOSTS file. Remember to add the contents of your current /etc/hosts file to the top of you new one, which will look like this:

Code: Select all	localhost
::1			localhost ip6-localhost ip6-loopback #[IPv6]
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters	raspberrypi
You can speed up a lot of web pages if you dont intend to use any social media sites (including logins) by adding:

Code: Select all
create /usr/share/applications/hosts.desktop with contents:

Code: Select all

[Desktop Entry]
Name=Edit Hosts File
GenericName=Edit Hosts File
Comment=Manage /etc/hosts file enties
Exec=gksudo leafpad /etc/hosts

1. Limit maximum open windows and tabs, and FAT WEB PAGES:

Especially if you use pages with Flash objects, limit you browser to 5 tabs (or 2 windows).

If you use Gmail, then stop the page load process and click the use standard html interface, which can also be set as your default interface. On Chrome 54 and below, you could "not log out" (by shutting the window), and just url back into Gmail because the cookie was kept. You cant do this in Chrome 55 (look through /usr/bin/chromium-browser), and if you use Gmail on another computer, clicking use standard html interface is a better option. is FAT. is FAT. is FAT. Any site that uses Wordpress default (read: common) themes is FAT. A lot of blogging sites and news sites are FAT. Be aware that FAT websites can kill your browser, quickly putting it into kernel swap lock. One or Two of these sites in tabs/windows will still get you best performance, most of the time, if you're patient.

Even without Flash content and FAT web pages, over time the browser will become slower to respond to web content and clicks, can be between 2-4 hours, so shut it down periodically, clean the cache, start it up again.

2. Freeing swap memory

Most kernels can get into (what I call) kernel swap lock, espectially with web browsers, especially when pages contain flash objects. Newer kernels seem to hit this problem extremely quickly, and appears worse on SystemD based systems. With SystemD it does not seem to greatly enhance operations to exchange the (Raspian) default 100Mb swap file with a dedicated swap partition, as it does with other init daemons, but even those will succumb to the inevitable kernel swap lock if you run any web browsers for extended periods.

On a regular Raspberry Pi this is because of limited main memory, swap being on a usb device, and a web browser use of cache and/or internal task management, also on a usb device (being the same usb device).

You can manually free any used virtual memory, unless you would rather do a sudo restart. Exiting X-Windows is not enough to free swap memory, but it will free up used memory.
(from: How to Clear RAM Memory Cache, Buffer and Swap Space on Linux)
1. Clear PageCache only.

Code: Select all

$ sync; echo 1 > /proc/sys/vm/drop_caches
2. Clear dentries and inodes.

Code: Select all

$ sync; echo 2 > /proc/sys/vm/drop_caches
3. Clear PageCache, dentries and inodes.

Code: Select all

$ sync; echo 3 > /proc/sys/vm/drop_caches
After all apps a closed, if you want to clear swap space, you can run the following command:

Code: Select all

$ dphys-swapfile swapoff && dphys-swapfile swapon
or if you use linux swap partitions

Code: Select all

$ swapoff -a && swapon -a
The appropriate time to run the above command can be double checked useing the free command to see if free memory outways virtual memory usage:

Code: Select all

$ free
             total       used       free     shared    buffers     cached
Mem:        882780     848036      34744      98324       5476     231128
-/+ buffers/cache:     611432     271348
Swap:       102396      43980      58416
nope: 43980 is larger than 34744 and used is 848036

Code: Select all

$ free
             total       used       free     shared    buffers     cached
Mem:        882780      48036     834744      98324       5476     231128
-/+ buffers/cache:     611432     271348
Swap:       102396      43980      58416
yep: 43980 is smaller than 834744 and used is 48036

3. Clean browser cache before loading browser:

Reduce initial browsing slow-downs caused by waiting for cache by deleting contents of cache before starting browser (not contents of cache database):

Code: Select all

$ mkdir -p ~/bin
$ cd ~/bin
$ echo <<<EOF >~/bin/clean-chrome-cache\
cd ~/.cache/chromium/Default/Cache\
rm -Rf *\
$ ln -s clean-chrome-cache ccc
Use ccc. The same can be done with FireFox cache (in ~/.cache/mozilla/firefox/rdzsv519.default/) (if you dont run it with firejail --private /usr/local/bin/firefox)

You can empty cache before exiting every browser session, which will also clean the cache database (but who remembers to do that everytime)

4. Sandboxing your browser to reduce security breaches, and reduce CPU 100% load and limit use of resources like RAM and SWAP.

Sandbox by installing FireJail in this post:
HOW TO: install FireJail and sandbox any app
1. can be applied to any app, including Chromium-Browser
2. can limit memory usage
3. can limit CPU% usage
4. can limit swap usage
(from firejail man page)
A symbolic link to /usr/bin/firejail under the name of a program, will start the program in Firejail sandbox. The symbolic link should be placed in the first $PATH position. On most systems, a good place is /usr/local/bin directory. Example:

Make a firefox symlink to /usr/bin/firejail:

Code: Select all

$ ln -s /usr/bin/firejail /usr/local/bin/firefox
Verify $PATH

Code: Select all

$ which -a firefox
Starting firefox in this moment, automatically invokes “firejail firefox”. This works for clicking on desktop environment icons, menus etc. Use "firejail --tree" to verify the program is sandboxed.

Code: Select all

$ firejail --tree
1189:netblue:firejail firefox
  1190:netblue:firejail firefox
     1220:netblue:/bin/sh -c "/usr/lib/firefox/firefox"

Sandbox using Cgroups and SystemD:
Running Firefox in a cgroup (using systemd)
1. can be applied to any app, including Chromium-Browser
2. can limit memory usage
3. can limit CPU% usage
4. can limit swap usage
(from the above link)
Add /etc/systemd/system/user-firefox.slice:

Code: Select all

Description=Firefox Slice

# CPUQuota isn't available in systemd 208 (Fedora 20).
add user-firefox (requires Python)

Code: Select all

#!/usr/bin/env python3

import os
import pwd

user_info = pwd.getpwnam('pi')

env = os.environ.copy()
env['HOME'] = user_info.pw_dir

os.execle('/usr/bin/firefox', 'Firefox (tame)', env)
You can now run (or add/change firefox.desktop) with:

Code: Select all

sudo systemd-run --slice user-firefox.slice --scope ./user-firefox

5. Tweaking web browser settings.

Starting FireFox in safe mode with plugins disabled can help alot. However that is not practical for a lot of users or use cases, a better more permanent option is under about:config, search for https and change thier urls to h{space}ttps. Note that you might want to keep some of them, like those related to Healthcare, and the Addons link.
(see more here: How does one stop FF from maxing out CPU usage)

Their are alot of settings in Chrome also (chrome://settings), but there are even more under the hood setting in (the shell script) /usr/bin/chromium-browser. However be warned playing with the contents of /usr/bin/chromium-browser could stop Chromium from launching, so at least make a backup of it first.

PS feel free to add your own tips and techniques to this thread
Last edited by paulwratt on Fri Feb 10, 2017 6:05 pm, edited 1 time in total.

User avatar
Posts: 260
Joined: Sat Nov 07, 2015 8:01 am
Location: Sarasota, Florida

Re: HOW TO: improve browser experience

Thu Feb 09, 2017 11:38 am

If you use Chromium for Linux, you can skip all of the suggestions above and install 3 plugins which accomplish even more:

1) AdBlockPlus - blocks most ads and speeds up page loads
2) uMatrix - this is the king of disabling scripts and avoiding loading of bandwidth and CPU sucking ads. This has knowledge of most popular sites to block malware/ads, but you can customize it to each site. By default, all tracking/parasite scripts are disabled and Google/Facebook scripts are also disabled.
3) The Great Suspender - This plugin saves your memory by unloading idle tabs. This allows you to keep all of your tabs, but only has the current one loaded in memory. When you click on an unloaded tab, it will revive.

With those 3 plugins running in Chromium, you can actually have a good web browsing experience on resource-limited machines.
The fastest code is none at all :)

User avatar
Posts: 137
Joined: Fri Jun 12, 2015 12:15 am

Re: HOW TO: improve browser experience

Fri Feb 10, 2017 6:23 pm

all that stuff might be well and good, but there it adds resources and requires extra cpu time, and probably server pings for tracking too..

/etc/hosts uses no extra resources, except the space the file takes up. it gets processed every time there is ANY "connecting to .." anywhere on your system, not just Chrome (or FireFox if you use that).

I use some sites that update there ad services regularly, after I catch the first end point websites, I examine the page source for their javascript include, and block that, easily gets a month or more (looking at 2 years on one site).

what you describe is a solution for non-linux users, thanks for help them out btw.

by looking into some of the places described, you will begin to understand just how much data is being lost in excess bandwidth and tracking

swap memory info is not explicitly browser related, and can be applied if you use a lot of apps for whatever reason (like software development)

I use my Pi on a daily basis because there is no practical alternative for my needs


Return to “Advanced users”