Search code examples
wordpressprefetch

Does prefetching works with a post shortlink?


I want to prefetch the next post in WordPress. In the admin panel and in the Permalink settings, permalinks are set to show Day and name:

example.com/2021/12/25/post-1

Does prefetching works using a post short permalink:

<link rel="prefetch" href="http://example.com/?p=1">

instead of the regular post permalink:

<link rel="prefetch" href="http://example.com/2021/12/25/post-1">

Solution

  • Both are pointing to the same text/html request. The short permalink ?p=1 is actually a 301 HTTP status code permanent redirect towards the regular permalink.


    prefetch through the short permalink (eg: /?p=1)

    <link rel="prefetch" href="http://localhost/www/wordpress/?p=1">
    

    As it is a 301, you will prefetch both. 2 different text/html request will be made.

    enter image description here

    You can have a look at the network chrome console tab to test it on your own.


    prefetch through the regular permalink (eg: /hello-world/)

    <link rel="prefetch" href="http://localhost/www/wordpress/hello-world/">
    

    Only 1 text/html request will be made.


    In short

    Both are doing exactly the same thing. One is more direct, and less performances heavy than the other.

    You should have a look at the Prefetch MDN Web Docs and the Link prefetching FAQ to have a better understanding on how prefetch actually works.