wordpress 下一页

I've been working to make this blog more performant by lazy loading everything I can think of, placing CSS and JavaScript into the HTML, and using data URIs;  the common theme in these is reducing the number of requests on each page.  One request I noticed (and hadn't anticipated) coming from WordPress looked like this:

我一直在努力通过延迟加载我能想到的所有内容,将CSS和JavaScript放入HTML中以及使用数据URI来提高此博客的性能。 这些中的共同主题是减少每个页面上的请求数量。 我注意到(但没想到)来自WordPress的一个请求看起来像这样:


<link rel="next" href="https://davidwalsh.name/page/2/" />


Wordpress was essentially preloading the second listing page of my blog, assuming that people would click a link to page 2.  When looking at my blog stats, that was very rarely the case (probably because I list 15 items on the homepage, which is a lot), so why bother sending the request at all?  This bit of WordPress magic will prevent that LINK element from being used:

假设人们会单击页面2的链接,则WordPress本质上是预加载了我博客的第二个列表页面。在查看我的博客统计信息时,这种情况很少见(可能是因为我在主页上列出了15个项目,很多),那么为什么还要打扰发送请求呢? WordPress魔术的这一点将阻止使用该LINK元素:


// ... in functions.php...

// Prevent unwanted next and prev link downloads
if(function_exists('remove_action')) { 
	remove_action('wp_head', 'start_post_rel_link', 10, 0);
	remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); 
}


There are two function calls removed -- one to prevent the tag from being used on the homepage/listing pages, and the other used on single blog posts.  Of course removing this call isn't for everyone but since I'm trying to micro-optimize the site, I thought I'd cut it out.

删除了两个函数调用-一个用于防止在首页/列表页上使用该标记,另一个则在单个博客文章上使用。 当然,删除此呼叫并不适合每个人,但由于我正在尝试对网站进行微优化,因此我想将其删除。

翻译自: https://davidwalsh.name/prevent-wordpress-loading-pages

wordpress 下一页

更多推荐

wordpress 下一页_防止WordPress加载“下一页”