加速 FireFox 及 Chrome 的页面载入速度

12
2011
# 作者: riku / 本文采用CC BY-NC-SA 2.5协议授权,转载请注明本文链接

当你在浏览器中访问网页时,除了第一次会从服务器上下载全部的页面内容外,之后的访问同一网站时绝大部分文件都是从本地缓存中读取。所以基于这一原理,我们可以把浏览器的 cache 目录放置在 tmpfs 文件系统中,以便让其直接从内存中读取缓存数据,加快页面载入速度。

Ubuntu 下默认就启用了 tmpfs 文件系统, 挂载点为 /dev/shm ,容量一般为实际内存的一半。不过 tmpfs 不同于 ramdisk ,它除了可以使用 RAM 外,也可以使用交换分区。

在 Linux 下把 FireFox 及 Chrome 的 cache 目前放置到 /dev/shm 中很简单,只要修改一下相应的参数即可,以下是方法。

- FireFox

在地址栏中输入 about:config 后回车,然后点击右键新建一个 String , name 为 browser.cache.disk.parent_directory , value 为 /dev/shm/firefox

browser.cache.disk.parent_directory=/dev/shm/firefox

- Chrome

Chrome 则更加简单,只需要在启动快捷键里加一个参数就可以了 - -disk-cache-dir="/dev/shm/chrome/" 即可。

/opt/google/chrome/google-chrome --disk-cache-dir="/dev/shm/chrome/"

好了,当你重启 FireFox 或 Chrome 后 /dev/shm 下就会多了 firefox 及 chrome 这两个目录,这就是他们的 cache 目录,其容量会随着访问网站的增多而增大。

作者:riku

Bio: 关注新网络、Web2.0、移动应用;Nexus S/Andorid,iPad,FreeBSD,Ubuntu 用户;伪设计师,好推墙运动。
链接:Blog - Twitter - Facebook - 此作者的更多文章

33 Responses to 加速 FireFox 及 Chrome 的页面载入速度

Avatar

dxq83

Firefox 4.0b9 Firefox 4.0b9 GNU/Linux GNU/Linux

一月 12th, 2011 at 12:56 下午

重启电脑后是不是cache就没了

[Reply]

Google Chrome 10.0.634.0 Google Chrome 10.0.634.0 GNU/Linux GNU/Linux

riku Reply:

@dxq83, 是的,清空了。

[Reply]

Avatar

csslayer

Firefox 3.6.13 Firefox 3.6.13 GNU/Linux GNU/Linux

一月 12th, 2011 at 1:04 下午

看另外一篇文章说这个有问题。貌似会频繁的增删文件,导致最后内存爆掉。

[Reply]

Google Chrome 10.0.634.0 Google Chrome 10.0.634.0 GNU/Linux GNU/Linux

riku Reply:

@csslayer, 内存爆掉? 什么概念?坏掉?

[Reply]

Google Chrome 9.0.597.47 Google Chrome 9.0.597.47 Windows 7 Windows 7

9hills Reply:

@csslayer,

放心吧,内存本来就是动态的,也就是说内存本身就在以很高的速度在不停的整体重新写入。。一旦停止刷新,数据就会丢失

所以不用担心频繁读写导致内存损坏。。

[Reply]

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

依云 Reply:

@9hills, 刷新不是重新写入吧?记得只有在读出数据后才需要重新写入的。

[Reply]

Firefox 4.0b11 Firefox 4.0b11 Windows Vista Windows Vista

bsidb Reply:

@依云,
刷新其实就是一个读出再重新写入的过程,无论读、写与否,内存一直会自动经过一个时间后进行刷新操作。

[Reply]

Avatar

ledmirage

Chromium 8.0.552.224 Chromium 8.0.552.224 Ubuntu 10.10 x64 Ubuntu 10.10 x64

一月 12th, 2011 at 1:30 下午

N年前就在用 /dev/shm 做 Firefox cache了,一直没问题

[Reply]

Google Chrome 8.0.552.224 Google Chrome 8.0.552.224 GNU/Linux GNU/Linux

ikbear Reply:

@ledmirage, 正需要!

[Reply]

Avatar

木头

Google Chrome 9.0.597.45 Google Chrome 9.0.597.45 GNU/Linux GNU/Linux

一月 12th, 2011 at 3:24 下午

这样的话,cookies之类的东西呢?也会随着cache 一起被清空么。~

[Reply]

Google Chrome 10.0.634.0 Google Chrome 10.0.634.0 GNU/Linux GNU/Linux

riku Reply:

@木头, 不会, cookies 不在 cache 目录里。

[Reply]

Avatar

bachue

Google Chrome 8.0.552.224 Google Chrome 8.0.552.224 GNU/Linux GNU/Linux

一月 12th, 2011 at 3:33 下午

我感觉没用
有速度测试表明这确实可以加速吗?

[Reply]

Avatar

snowhawkyrf

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

一月 12th, 2011 at 3:48 下午

太给力了,谢谢!!虽然暂时没发现快了多少……

[Reply]

Avatar

Heiher

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.04 x64 Ubuntu 10.04 x64

一月 12th, 2011 at 4:11 下午

不错,效果肯定有的,用 dd 测试一下就知道 /dev/shm 的读写速度是非常快的。

[Reply]

Avatar

ledmirage

Namoroka 3.6 Namoroka 3.6 GNU/Linux x64 GNU/Linux x64

一月 12th, 2011 at 6:06 下午

相对网速来说一般硬盘做 cache 以经很快了,但我还是会用 /dev/shm ,除了加速外可以减少硬盘的读写,相对延长硬盘寿命

[Reply]

Google Chrome 9.0.597.47 Google Chrome 9.0.597.47 Windows 7 Windows 7

9hills Reply:

@ledmirage,

这个有点道理---硬盘是机械式的,尽量减少频繁读写是正道

[Reply]

Avatar

MOPVHS

Google Chrome 8.0.552.224 Google Chrome 8.0.552.224 Windows 7 Windows 7

一月 12th, 2011 at 8:41 下午

咦,Twitter上过来,不是新发表的~~~

[Reply]

Avatar

依云

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

一月 12th, 2011 at 9:00 下午

我不明白把 cache 全部放内存里哪里比放磁盘里快了?文件访问速度是提高了很多,但是 cache 是做什么的?重启下就清空了不等于是把所有 cache 的过期时间设为了机器连续在线的时间?

[Reply]

Avatar

Terry

Chromium 10.0.636.0 Chromium 10.0.636.0 Ubuntu 11.04 x64 Ubuntu 11.04 x64

一月 13th, 2011 at 5:42 上午

光把cache放到tmpfs貌似性能不会有太大的提高,因为cache机制。第一次访问会在本地存cache,之后再访问就会检查,若已经访问过,cache中有才会从cache(tmpfs)中都,也就是说只有第一次写入和之后再访问才会起作用。

其实彻底一点的做法是把整个Chrome或者Firefox的user-dir或者profile放到tmpfs,不过这么做得时常做好同步把数据保存到硬盘,否则一旦出问题数据都丢了,囧

[Reply]

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

依云 Reply:

@Terry, 这样有个 speedfox 脚本的。

[Reply]

Avatar

bachue

Google Chrome 8.0.552.237 Google Chrome 8.0.552.237 Windows XP Windows XP

一月 13th, 2011 at 3:12 下午

我是感觉这种做法只会减速(因为一旦关机内存内容就没了),不会加速(因为linux的cache机制)。除非有速度测试表明这确实提升速度,否则我难以相信。
把/tmp挂在tmpfs下才是比较好的提速方法吧。

[Reply]

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

依云 Reply:

@bachue, 那个应该是浏览器的 cache 机制吧。在 Linux 下如果内存大的话,我估计浏览器经常访问的那些文件都会自动到I/O cache里去。

PS: 我的 /tmp 早就是 tmpfs 了。

[Reply]

Avatar

snowhawkyrf

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

一月 15th, 2011 at 1:20 下午

请问怎么把thunderbird的缓存也改掉呢?我主要是想减少硬盘的读写

[Reply]

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

snowhawkyrf Reply:

@snowhawkyrf,
搞定啦,有个雷鸟的扩展:viewabout,非常赞,和火狐一样的设置就可以了。

[Reply]

Avatar

bychen009

Google Chrome 10.0.612.1 Google Chrome 10.0.612.1 GNU/Linux GNU/Linux

一月 16th, 2011 at 1:07 下午

请问截图中的字体是什么?很喜欢啊~

[Reply]

Google Chrome 10.0.628.0 Google Chrome 10.0.628.0 GNU/Linux x64 GNU/Linux x64

riku Reply:

@bychen009, 英文字体吗?那是 Ubuntu 10.10 默认字体,字体名字就 叫 Ubuntu 。

[Reply]

Google Chrome 10.0.612.1 Google Chrome 10.0.612.1 GNU/Linux GNU/Linux

bychen009 Reply:

@riku, 额,多谢。我是说截图中的中文字体,就是“分享到。。。”右边的那部分~,我没找到自带的字体中有这种点阵字体的。

[Reply]

Google Chrome 10.0.634.0 Google Chrome 10.0.634.0 GNU/Linux GNU/Linux

riku Reply:

@bychen009, 这个倒不清楚,这是别人做的。

[Reply]

Avatar

colt

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

一月 17th, 2011 at 1:29 下午

@riku, 我这样设置后发现Firefox访问Gmail的时候Gmail的载入进度条一直不动,只能使用html视图来访问Gmail,关掉后Firefox访问Gmail恢复正常. 不知道是为什么

[Reply]

Google Chrome 10.0.634.0 Google Chrome 10.0.634.0 GNU/Linux GNU/Linux

riku Reply:

@colt, 这个可能是和网络线路有关,要不用回原来的方法再试试。

[Reply]

Firefox 3.6.13 Firefox 3.6.13 Ubuntu 10.10 Ubuntu 10.10

colt Reply:

@riku, 线路问题可以排除,使用Chromimum(未修改缓存地址)访问一切正常,不知道是GFW的影响还是FF本身的问题,再测试看看把

[Reply]

Avatar

Diigo Diary 01/20/2011 « Benx Blog

XML-RPC XML-RPC

一月 20th, 2011 at 8:34 上午

[...] 加速 FireFox 及 Chrome 的页面载入速度 [技巧] | Wow!Ubuntu [...]

Avatar

將 Linux 的 Firefox、Chrome 暫存區設定到 RAM 裡面 | Tsung's Blog

WordPress 3.2.1 WordPress 3.2.1

一月 5th, 2012 at 3:50 下午

[...] 由此篇文章見到的是另外一種方式: 加速 FireFox 及 Chrome 的頁面載入速度 [...]

Comment Form

top

无觅相关文章插件,快速提升流量