pasckr 发表于 2016-5-12 18:19:31

WordPress实现HTML5预加载






              HTML5引入了预加载页面技术,可以大幅度提高您的网站加载时间以及速度。
http://img10.3lian.com/d0214/file/2011/11/04/c8583f084170fa0a594999fc9fc7dc59.jpg
WordPress实现HTML5预加载方法很简单,把下面代码:
<?php if (is_archive() && ($paged > 1) && ($paged < $wp_query->max_num_pages)) { ?>   
<link rel=&quot;prefetch&quot; href=&quot;<?php echo get_next_posts_page_link(); ?>&quot;>   
<link rel=&quot;prerender&quot; href=&quot;<?php echo get_next_posts_page_link(); ?>&quot;>   
<?php } ?> 加到header.php模版,<head> 与</head>之间。
还可以根据自己的需要对上面的代码进行适当的修改,例如加个判断预读首页等。
<?php if (is_archive() && ($paged > 1) && ($paged < $wp_query->max_num_pages)) { ?>   
<link rel=&quot;prefetch&quot; href=&quot;<?php echo get_next_posts_page_link(); ?>&quot;>   
<link rel=&quot;prerender&quot; href=&quot;<?php echo get_next_posts_page_link(); ?>&quot;>   
<?php } elseif (is_singular()) { ?>   
<link rel=&quot;prefetch&quot; href=&quot;<?php bloginfo('home'); ?>&quot;>   
<link rel=&quot;prerender&quot; href=&quot;<?php bloginfo('home'); ?>&quot;>   
<?php } ?> 由于预加载是HTML5的一部分,目前并不是所有浏览器都支持,比如:InternetExplorer就不行了。而Firefox、chrome和opera支持该技术。因此如果访问者的浏览器不支持预加载,将什么效果也没有。
至于真的有什么实际效果只能自己去体会了。
英文地址:Mastering HTML5 Prefetching
翻译地址:http://zmingcx.com/
页: [1]
查看完整版本: WordPress实现HTML5预加载