<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>-Flyぁ梦- &#187; Firefox</title>
	<atom:link href="http://blog.11034.org/tag/firefox/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.11034.org</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jun 2025 08:59:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>加速你的网站，Google page speed</title>
		<link>http://blog.11034.org/2010-12/google_page_speed.html</link>
		<comments>http://blog.11034.org/2010-12/google_page_speed.html#comments</comments>
		<pubDate>Fri, 03 Dec 2010 17:44:00 +0000</pubDate>
		<dc:creator><![CDATA[-Flyぁ梦-]]></dc:creator>
				<category><![CDATA[博客建站]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[域名]]></category>

		<guid isPermaLink="false">http://blog.stariy.org/?p=689</guid>
		<description><![CDATA[前些日子接触了Google webmasters，看到了page speed，于是下载试用。page spee [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>前些日子接触了Google webmasters，看到了page speed，于是下载试用。page speed是Firefox下Firebug的一个附件，依赖于Firebug。很好用，能迅速列出所有影响网页加载速度的原因及优化方法，然后分三部分：红色警告、黄色警告和绿色通过。对于网站管理员来说十分值得一用，大力推荐。</p>
<p>Google page speed的官方网页：<a href="http://code.google.com/speed/page-speed/">http://code.google.com/speed/page-speed/</a>，包括下载和文档。</p>
<p><span id="more-689"></span></p>
<p>page speed提出的几个方面的加速方法，主要针对网站的静态资源，如css、js、image和静态html等</p>
<ul>
<li>尽量合并css和js文件</li>
</ul>
<p>理由很简单，数量少了，http请求就好了，当然就加速了。不过这点基本很难优化，多个js和css往往属于不同的模块，所以一个模块下尽量只有1个css文件和1个js文件吧。page speed给出（红色警告）。</p>
<ul>
<li>gzip压缩css、js、image文件</li>
</ul>
<p>gzip技术可以将css和js文件压缩减少大约60%以上的大小，我的博客首页被提示压缩可节省68%的大小。压缩的副作用是多吃CPU，压缩率越高CPU吃的也越多。要开启gzip压缩，需要在apache、nginx等web服务器上配置，比较有技术性。page speed给出（红色警告）。</p>
<ul>
<li>缓存，Last-Modified、Expires和Etag</li>
</ul>
<p>浏览器缓存又可以减少大量的http对静态资源的请求，通过设置Last-Modified、Expires和Etag这几个http头属性，可以将基本不会变化的静态资源缓存个把个月。此些设置也要在web服务器上配置，当然如果是Java或Python某些框架可以对静态资源的URL也抓到的可以通过程序来实现，php wordpress的话就不知道了。page speed给出（红色警告）。</p>
<ul>
<li>优化css（黄色警告）</li>
</ul>
<p>把css放在文档head中；避免@import；选择符层次不要太深，像div table tr td .center{ } 这样。需要较高css技巧恩。page speed给出（黄色警告）。</p>
<p>前面几个优化点基本还是算广为人知的，下面几个优化点我也是第一次知道，很有意思。</p>
<ul>
<li>从一个永不设置cookie的域获取静态资源</li>
</ul>
<p>查了文档后，大致明白了原因。因为静态资源只有http头，而没有content，所以带cookie插入的域的http包就会比较大，cookie域在http包中的比例一般比较大。还有可能因为cookie的原因导致Last-Modified修改而影响缓存？我猜的&#8230;于是Google推荐用2个域名，专用1个域名来获取静态资源，然后把CNAME设置为网站主域名，就像Google的gstatic.com。page speed给出（红色警告）。</p>
<ul>
<li>用css sprites处理静态图片资源</li>
</ul>
<p>不知道什么是css sprites的参见：<a href="http://baike.baidu.com/view/2173476.htm">http://baike.baidu.com/view/2173476.htm</a>。简单就是将所以零碎的小图片合并成一个大图片，然后用csss属性进行精确定位分割。这样可以大大减少对图片的http请求，不过你的css技术可要过硬哦。page speed给出（红色警告）。</p>
<ul>
<li>*可缓存、压缩的资源需要有一个&#8221;Vary: Accept-Encoding&#8221;</li>
</ul>
<p>只有大概了解，Google的说法这样静态资源会生成2份，1份压缩后的，1份未压缩的，这样服务器端可以按照客户端的不同要求来选择发送哪一个。page speed给出（黄色警告）。但也在网上有看到如果存在这个属性，cache命中率会降低，不甚理解。打个*号表示此项有争议 = =</p>
<p>看到如此多被page speed警告，大多数还是红色警告，不甚手痒想试着优化，但是由于是虚拟主机的空间没法自己操纵Apache，CPanel貌似也没有提供相关支持，于是更加助长了想要买一个VPS自己搭系统的欲望，但是好贵啊好贵T_T</p>
<h4  class="related_post_title">看看 Firefox , Google , 域名</h4><ul class="related_post"><li>2015-07-29 -- <a target="_blank" href="http://blog.11034.org/2015-07/beian.html" title="域名备案和博客迁移至国内">域名备案和博客迁移至国内</a></li><li>2013-10-17 -- <a target="_blank" href="http://blog.11034.org/2013-10/google.html" title="Google校招">Google校招</a></li><li>2011-10-14 -- <a target="_blank" href="http://blog.11034.org/2011-10/google_2012_campus.html" title="Google2012校招笔试">Google2012校招笔试</a></li><li>2011-06-11 -- <a target="_blank" href="http://blog.11034.org/2011-06/google_doodle_guitar.html" title="2011-6-9 Google Doodle之电子琴">2011-6-9 Google Doodle之电子琴</a></li><li>2011-01-08 -- <a target="_blank" href="http://blog.11034.org/2011-01/search_engine.html" title="2个月的搜索引擎状况">2个月的搜索引擎状况</a></li></ul><h4 class="related_post_title">看看 博客建站 </h4><ul class="related_post"><li>2015-07-29 -- <a target="_blank" href="http://blog.11034.org/2015-07/beian.html" title="域名备案和博客迁移至国内">域名备案和博客迁移至国内</a></li><li>2011-06-08 -- <a target="_blank" href="http://blog.11034.org/2011-06/dreamhost.html" title="新空间Dreamhost">新空间Dreamhost</a></li><li>2011-03-18 -- <a target="_blank" href="http://blog.11034.org/2011-03/blog_first_anniversary.html" title="庆祝博客上线一周年">庆祝博客上线一周年</a></li><li>2011-01-08 -- <a target="_blank" href="http://blog.11034.org/2011-01/search_engine.html" title="2个月的搜索引擎状况">2个月的搜索引擎状况</a></li><li>2010-11-28 -- <a target="_blank" href="http://blog.11034.org/2010-11/domain_change_to_stariy-org.html" title="域名更换">域名更换</a></li>]]></content:encoded>
			<wfw:commentRss>http://blog.11034.org/2010-12/google_page_speed.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>wp-postviews的防刷新的处理</title>
		<link>http://blog.11034.org/2010-09/wp-postviews_do_with_page_refresh.html</link>
		<comments>http://blog.11034.org/2010-09/wp-postviews_do_with_page_refresh.html#comments</comments>
		<pubDate>Tue, 14 Sep 2010 15:11:34 +0000</pubDate>
		<dc:creator><![CDATA[-Flyぁ梦-]]></dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://blog.stariy.info/?p=411</guid>
		<description><![CDATA[wp-postviews是很好用的一款用来统计每篇文章pv（page view）的插件，还能在sidebar提 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>wp-postviews是很好用的一款用来统计每篇文章pv（page view）的插件，还能在sidebar提供一个top view的小工具，十分赞，是为数不多的wordpress博客必备的插件之一。不过它有一个不足，就是pv不防刷新，即你对同一篇文章短时间内刷新几次，就是几个pv，而这样的pv是毫无意义的，就起了个念头来改善一下。<span id="more-411"></span></p>
<p>很显然，要记录访问者短时间内访问的每一篇文章，cookie是必须出场的，当然记录的是每篇文章的post id号。能读取到cookie中的所有已阅的文章id，就可以控制是否对此文章的pv更新+1了，在wp-postviews的wp-postviews.php里的process_postviews()函数里插入一个自己的判断函数即可。</p>
<p>然后一个很大的问题就是何时写入cookie并点击新文章时更新cookie，在wp-postviews.php里面是不行的，因为前面已经有输出了，此处不能写入cookie，比较棘手。然后在主题的single.php试了一下，居然可以，那就在这里写cookie吧。由于在主题的大循环（single.php的显示文章部分）外，无法使用get_the_ID()这个API，而基本上所有的博客都会采用路径重写，而不是默认的/?p=id这种形式，后来发现，在single.php可以使用一个$posts的全局变量，里面有本次请求的基本参数，不了解的同学去print_r()就知道啦，解决了文章id的获取，就可以使用setcookie来写入和更新cookie了。</p>
<p>试了一下基本没问题，IE、FF、Chrome都支持。很奇怪的一点，为什么single.php是可以操纵写入cookie呢？照理来说，这个文件之前已经有HTML输出了，是应该不能写cookie的，而且我尝试在single.php和wp-postviews.php 2个文件的顶端同时调用exit()，是后者的先出来。这说明先调到了插件计数，然后再显示页面的，但却前面的不能写cookie，后面的反而可以，疑惑了&#8230;不知道wordpress是怎么处理的 <img src="http://blog.11034.org/wp-includes/images/smilies/icon_question.gif" alt=":?:" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>技术部分就到这儿了，另外发现一个奇怪的地方，仅在于Firefox。进入一篇文章的页面，居然cookie里面有2个id，后来发现第二个id是此篇文章的下一篇，即head中&lt;link rel=&#8217;next&#8217; /&gt;标签。百度后发现，浏览器会根据这标签提前加载页面，相当于同时打开了2篇文章。个人感觉这个功能很鸡肋，起码在wordpress中是如此，看那篇文章完全是因为文章的内容来吸引访问者，又不是RSS，按顺序一篇一篇读下去。不知道算是FF的一个优势还是一个败笔。</p>
<p>贴一下代码：<br />
wp-postviews.php的process_postviews()中$post初始化后添加2行：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>check_cookie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>wp-postviews.php加入函数：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> check_cookie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$COOKNAME</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'CookieViews'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$cookie</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$COOKNAME</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>single.php写cookie部分，放在最顶端</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$COOKNAME</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'CookieViews'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$TIME</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">24</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$PATH</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$posts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$expire</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$TIME</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cookie</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$COOKNAME</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$COOKNAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$expire</span><span style="color: #339933;">,</span> <span style="color: #000088;">$PATH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$COOKNAME</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookie</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$expire</span><span style="color: #339933;">,</span> <span style="color: #000088;">$PATH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4  class="related_post_title">看看 cookie , Firefox</h4><ul class="related_post"><li>2010-12-04 -- <a target="_blank" href="http://blog.11034.org/2010-12/google_page_speed.html" title="加速你的网站，Google page speed">加速你的网站，Google page speed</a></li><li>2010-03-18 -- <a target="_blank" href="http://blog.11034.org/2010-03/ie_is_tragedy.html" title="IE就是个悲剧…">IE就是个悲剧…</a></li></ul><h4 class="related_post_title">看看 Wordpress </h4><ul class="related_post"><li>2014-03-12 -- <a target="_blank" href="http://blog.11034.org/2014-03/new_url_to_template.html" title="wordpress改源码实现自定义URL到自定义页面">wordpress改源码实现自定义URL到自定义页面</a></li><li>2013-12-05 -- <a target="_blank" href="http://blog.11034.org/2013-12/wp-sns-share_2-8.html" title="wp_sns_share更新至2.8，添加小功能">wp_sns_share更新至2.8，添加小功能</a></li><li>2013-02-14 -- <a target="_blank" href="http://blog.11034.org/2013-02/wp_zjuem_in_wordpress.html" title="wp-zjuem，zju cc98表情系统 in wordpress">wp-zjuem，zju cc98表情系统 in wordpress</a></li><li>2012-09-26 -- <a target="_blank" href="http://blog.11034.org/2012-09/wordpress_post_actions.html" title="wordpress发布文章时的Action事件">wordpress发布文章时的Action事件</a></li><li>2012-08-29 -- <a target="_blank" href="http://blog.11034.org/2012-08/wp-sns-share_2-6.html" title="wp_sns_share更新至2.6，增加图片同步">wp_sns_share更新至2.6，增加图片同步</a></li>]]></content:encoded>
			<wfw:commentRss>http://blog.11034.org/2010-09/wp-postviews_do_with_page_refresh.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
