Added fake AJAX to the blog, and finally removed it

text

A week ago, I added a piece of pseudo Ajax to my blog, and finally removed it.

In terms of code, the asynchronous loading method used by most WordPress themes is "fake Ajax". Although they have the effect of not refreshing and jumping, they cannot save traffic. The principle of these codes is much the same: first obtain the complete page asynchronously, then select the main elements, and finally fill the main contents to the current page. In this process, the browser still needs to get the full page, without saving traffic.

An ideal situation is to obtain the Json asynchronously, then parse it and populate it to the current page. In this way, it can not only save traffic and speed up, but also achieve the effect of not refreshing the jump. To implement this function on WordPress, you need to add a lot of content. It is better to write a blog program if you have time to add it. I don't understand the front and back ends, so I'm too lazy to do it.

At present, Google Adsense does not support Ajax: block ads are OK, and you can manually call the Push method to brush them. However, if you place automatic ads, the second time you call Push, you will report an enable_page_level_ads conflict and cannot refresh.

If you want to build a whole station music player or something similar, you'd better add pseudo Ajax. If you use Adsense, Ajax needs to be considered as appropriate.

About loading speed: My blog is using the Wp Super Cache plug-in. The article is static. Even if there is no asynchronous loading, the speed should not be too slow. The small water pipe of Tencent Cloud student machine occasionally gets stuck, but it doesn't hurt.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/4333.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*

Comment area

  1. Panda A 12-13 16:31 reply

    Ha ha, I also use fake PJAX, and still request a full page. There was a time when the server only returned the corresponding part after detection by marking in the header, but it was troublesome to write this way.
    It seems that Typecho does not have a native JSON API. It is said that Ghost has. It should be good to write a complete single page website.

    • Ghosin 12-23 08:45 reply

      It's the same as a fake PJAX victim, but Hexo doesn't have a back end and seems unable to detect whether a full page is returned... Maybe you can generate an additional article, json, and then load the rendered article, but you need to rewrite your own pjax... I'll wait to change vuepass 🙂

  2. Sparrow 12-25 09:33 reply

    Try the front-end SPA (vue, angular, react, etc.), and then use wp rest to realize data interaction. It should be pure JSON. As for Google Adsense, I remember that there are plug-ins. For example, if vue is used, you can use vue google adsense and other solutions ( ̄ ▽ ̄;)

  3. Indeed
    Even the theme I modified is the same.

    I found that the AJAX of this blogger's theme was written by himself, which really saves traffic.
    https://blog.qwq.moe/

    • hare 01-09 01:40 reply

      The Typecho routing made by the mosquito bosses is their daily operation.