Mockingbird beginThe theme is accelerated by Qiniu Cloud CDN, which leads to the failure of Ajax comments

The comments on this blog were abnormal after Qiniu Cloud CDN acceleration was enabled yesterday, and there was a problem that you cannot comment.

Comment failure prompt code

{"error":"get from image source failed: E405"}

After searching on the Internet, I found a solution in Shimeng blog. The reason why the Mockingbird start theme is accelerated by Qiniu Cloud CDN, which leads to the invalidation of Ajax comments, is that the theme uses Ajax comment effects, while the comments-ajax.js file and comments-ajax-qt.js file are cached on the Qiniu server, which leads to the failure of Ajax comments.知更鸟begin主题用七牛云cdn加速导致Ajax评论失效解决办法

Method 1: Modify the comments-ajax.js file

Find the following code in the comments-ajax.js file:

  1. var ? i?=?0,?got?=?-1,?len?=?document.getElementsByTagName('script').length;
  2. while ? (?i?<=?len?&&?got?==?-1){
  3. ???? var ? js_url?=?document.getElementsByTagName('script')[i].src,
  4. ???????????? got?=?js_url.indexOf('comments-ajax.js');? i++?;
  5. }

Add the following code after it:

  1. js_url?=?js_url.replace('cdn.wosn.net','wosn.net');

Pay attention to changing to your own seven cow acceleration address and website address. Among them, Change cdn.wosn.net to the secondary domain name provided by your Qiniu, and change wosn.net to your WordPress site domain name

After adding, it will be as follows:

  1. var ? i?=?0,?got?=?-1,?len?=?document.getElementsByTagName('script').length;
  2. while ? (?i?<=?len?&&?got?==?-1){
  3. ???? var ? js_url?=?document.getElementsByTagName('script')[i].src,
  4. ???????????? got?=?js_url.indexOf('comments-ajax.js');? i++?;
  5. }
  6. /*Js_url is adding Qiniu Cloud CDN acceleration, unable to comment and modify*/
  7. js_url?=?js_url.replace('cdn.wosn.net','wosn.net');
  8. var ? edit_mode?=?'1',? //? Re edit mode (?'1 '=Open;?'0'=Close)

Then delete the comments-ajax.js file in Qiniu's cloud acceleration and re cache it to solve the problem of invalidation of Ajax comments caused by the use of Qiniu's cloud cdn acceleration for the robin start theme.

Method 2: Add cdn image exceptions

The above method modifies the js file method, but it takes too long to take effect. Qiniu still has a process of refreshing the cache, and can't see the effect immediately. The following method is to directly exclude the js file from the image list. Although one more js file is added when loading, the effect is immediate.

This blog uses the wp super cache plug-in to add images. The addition exclusion is shown in the following figure:
知更鸟begin主题用七牛云cdn加速导致Ajax评论失效解决办法

I make a record myself and hope it can help everyone.

 Watson Blog
  • This article is written by Published on August 12, 2017 02:19:54
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/1.html

Comment