Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit fcd8125

Browse files
committed
Fixed JSON requests
1 parent 41ea13f commit fcd8125

File tree

8 files changed

+66
-110
lines changed

8 files changed

+66
-110
lines changed

README.md

Lines changed: 18 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
# defer-wordpress
22

3-
🥇 Latest website optimization technologies by experienced web experts. 💯 SEO friendly. 🔰 Very easy to use.
3+
🥇 Harness the latest WordPress optimization tech, 💯 SEO-friendly, and 🔰 effortlessly user-friendly!
44

55
Download: [https://wordpress.org/plugins/shins-pageload-magic/](https://wordpress.org/plugins/shins-pageload-magic/)
66

77
![HitCount](http://hits.dwyl.com/shinsenter/defer-wordpress.svg)
88
![GitHub](https://img.shields.io/github/license/shinsenter/defer-wordpress.svg)
99

1010
![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/shinsenter/defer-wordpress.svg)
11-
[![Post an issue](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/shinsenter/defer-wordpress/issues)
11+
[![Post an issue](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://code.shin.company/defer-wordpress/issues)
1212
![GitHub issues](https://img.shields.io/github/issues-raw/shinsenter/defer-wordpress.svg)
1313
![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer-wordpress.svg)
1414

15-
⚡️ A native, blazing fast lazy loader. ✅ Legacy browsers support (IE9+). 💯 SEO friendly. 🧩 Lazy-load everything.
15+
⚡️ Experience the speed of a native, lightning-fast lazy loader. ✅ Backward compatibility for legacy browsers (IE9+). 💯 SEO-friendly. 🧩 Lazy-load everything.
1616

17-
This plugin helps you to optimize everything like image tags, video, audio, iframes as well as stylesheets, and JavaScript.
17+
This plugin empowers you to optimize various elements, including image tags, videos, audio, iframes, stylesheets, and JavaScript.
1818

19-
This plugin incorporates tips used a lot by experienced web experts, as well as making the most of the latest web technologies in lazy-loading resources on the page.
19+
Leveraging tips endorsed by seasoned web experts and harnessing the latest web technologies for resource lazy-loading, this plugin ensures your website operates at peak efficiency.
2020

21-
Rate [5 stars (⭐️⭐️⭐️⭐️⭐️)](https://wordpress.org/support/plugin/shins-pageload-magic/reviews/?filter=5#new-post) if you guys like it.
21+
If you find this plugin valuable, please consider leaving a [5-star review (⭐️⭐️⭐️⭐️⭐️)](https://wordpress.org/support/plugin/shins-pageload-magic/reviews/?filter=5#new-post).
2222

2323

2424
## Good points
2525

26-
- 🔰 Very easy to use
27-
- 🚀 Native API, blazing fast
28-
- 👍 No dependencies, no jQuery
29-
-Supports legacy browsers (IE9+)
30-
- 🎯 [Core Web Vitals](https://web.dev/vitals/) friendly
31-
- 🧩 Lazy load almost everything
26+
- ⚡️ Native API, blazing fast
27+
- 👍 Legacy browsers support (IE9+)
28+
- 🥇 SEO friendly
29+
-Very easy to use
30+
- 💯 No dependencies, no jQuery
31+
- 🤝 Works well with your favorite frameworks
3232
- 🧩 Uses [IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) for optimized CPU usage
3333
- 🏞 Supports for responsive images, both `srcset` and `sizes` attributes
34-
- 🤝 Works well with your favorite frameworks
3534

3635
💡 Tip: To archive better result, you should consider disabling all optimization features (Eg. lazy-loading, HTML minification, JS minification, etc.) by other plugins.
3736

@@ -50,90 +49,26 @@ This plugin also works perfectly on popular browsers, including Internet Explore
5049
- 📱 Android 4+
5150
- 📱 iOS 3.2+
5251

52+
5353
## Powered by defer.js, defer.php
5454

55-
[defer.js](https://github.com/shinsenter/defer.js)
55+
[defer.js](https://code.shin.company/defer.js)
5656
🥇 A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript.
5757

58-
[defer.php](https://github.com/shinsenter/defer.php)
58+
[defer.php](https://code.shin.company/defer.php)
5959
🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page.
6060

61-
### Key features
62-
63-
- [x] Embed [defer.js](https://github.com/shinsenter/defer.js) plugin
64-
- [x] Normalize DOM elements
65-
- [x] Fix missing meta tags
66-
- [x] Fix missing media attributes
67-
- [x] Preconnect to required origins
68-
- [x] Preload key requests
69-
- [x] Prefetch key requests
70-
- [x] Browser-level image lazy-loading for the web
71-
- [x] Lazy-load offscreen and hidden iframes
72-
- [x] Lazy-load offscreen and hidden videos
73-
- [x] Lazy-load offscreen and hidden images
74-
- [x] Lazy-load CSS background images
75-
- [x] Reduce the impact of JavaScript
76-
- [x] Defer non-critical CSS requests
77-
- [x] Defer third-party assets
78-
- [x] Add fallback `<noscript>` tags for lazy-loaded objects
79-
- [x] Add custom HTML while browser is rendering the page (splashscreen)
80-
- [x] Attribute to ignore optimizing the element
81-
- [x] Attribute to ignore lazyloading the element
82-
- [x] Optimize AMP document
83-
- [x] Minify HTML output
84-
85-
86-
## Why should I lazy-load my content?
87-
88-
The loading of contents on web page may make your load speed more slow, no one likes staring at a blank white page; users are impatient and will leave quickly.
89-
90-
Lazy loading content on web page can help reduce resource contention and improve performance.
91-
92-
93-
## Why should I use this plugin?
94-
95-
This plugin supports you to handle some common tips to help your website optimize the download of on-page resources.
96-
97-
These tips are published at [following website](https://web.dev/) by Google Developers, if you are interested you can consult to understand more about website optimization.
98-
99-
You can also manually implement these tips your-self, but it takes a lot of time and requires a lot of expertise.
100-
101-
102-
## How does this plugin work?
103-
104-
This plugin helps you to optimize everything like image tags, video, audio, iframes as well as stylesheets, and JavaScript.
105-
106-
This plugin incorporates tips used a lot by experienced web experts, as well as making the most of the latest web technologies in lazy-loading resources on the page.
107-
108-
Among them are creating "data-src" attributes to laza-load the media, even the [loading="lazy" feature](https://web.dev/browser-level-image-lazy-loading/) recently introduced by Google Developers.
109-
110-
111-
## High performance and accuracy
112-
113-
In addition, this plugin uses DOM to process the website structure so it produces accurate results and is faster than any other plugin that uses HTML text processing.
114-
115-
You can give it a try and I believe you will be surprised by the results it brings to your website.
116-
117-
118-
## Stable performance and high compatibility
119-
120-
We have tested this plugin with quite a few others and have not found any significant conflicts.
121-
122-
For best use of this plugin, you should consider disabling all optimization features (Eg. lazy-loading, HTML minification, JS minification, etc.) by other plugins.
123-
124-
We recommend you use it with another page-caching plugin for best performance.
125-
12661

12762
## Support my activities
12863

12964
[![Donate via Paypal](https://img.shields.io/badge/Donate-Paypal-blue)](https://www.paypal.me/shinsenter)
13065
[![Become a sponsor](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/appseeds)
131-
[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://github.com/shinsenter/defer-wordpress/stargazers)
132-
[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://github.com/shinsenter/defer-wordpress/issues/new)
66+
[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://code.shin.company/defer-wordpress/stargazers)
67+
[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://code.shin.company/defer-wordpress/issues/new)
13368

13469
---
13570

13671
Released under the GNU General Public License v2 license.
137-
https://github.com/shinsenter/defer-wordpress/blob/master/LICENSE
72+
https://code.shin.company/defer-wordpress/blob/master/LICENSE
13873

13974
Copyright (c) 2019 Mai Nhut Tan &lt;[[email protected]](mailto:[email protected])&gt;

README.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ This plugin also works perfectly on popular browsers, including Internet Explore
5454

5555
### Powered by defer.js, defer.php
5656

57-
[defer.js](https://github.com/shinsenter/defer.js)
57+
[defer.js](https://code.shin.company/defer.js)
5858
🥇 A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript.
5959

60-
[defer.php](https://github.com/shinsenter/defer.php)
60+
[defer.php](https://code.shin.company/defer.php)
6161
🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page.
6262

6363
#### Key features
6464

65-
- [x] Embed [defer.js](https://github.com/shinsenter/defer.js) plugin
65+
- [x] Embed [defer.js](https://code.shin.company/defer.js) plugin
6666
- [x] Normalize DOM elements
6767
- [x] Fix missing meta tags
6868
- [x] Fix missing media attributes
@@ -92,14 +92,14 @@ Keep up-to-date with new releases:
9292

9393
[Donate via Paypal](https://www.paypal.me/shinsenter)
9494
[Become a sponsor](https://www.patreon.com/appseeds)
95-
[Become a stargazer](https://github.com/shinsenter/defer-wordpress/stargazers)
96-
[Report an issue](https://github.com/shinsenter/defer-wordpress/issues/new)
95+
[Become a stargazer](https://code.shin.company/defer-wordpress/stargazers)
96+
[Report an issue](https://code.shin.company/defer-wordpress/issues/new)
9797

9898

9999
---
100100

101101
Released under the GNU General Public License v2 license.
102-
[https://github.com/shinsenter/defer-wordpress/blob/master/LICENSE](https://github.com/shinsenter/defer-wordpress/blob/master/LICENSE)
102+
[https://code.shin.company/defer-wordpress/blob/master/LICENSE](https://code.shin.company/defer-wordpress/blob/master/LICENSE)
103103

104104
Copyright (c) 2019 Mai Nhut Tan &lt;[[email protected]](mailto:[email protected])&gt;
105105

@@ -163,6 +163,8 @@ We also recommend using it in conjunction with a page-caching plugin for the bes
163163

164164
== Changelog ==
165165

166+
2.6: Fixed bugs related to JSON requests
167+
166168
2.5: Addressed deprecation errors for compatibility with newer PHP versions.
167169

168170
2.4: Made minor updates and improvements to the documentation.
@@ -171,7 +173,7 @@ We also recommend using it in conjunction with a page-caching plugin for the bes
171173

172174
2.2: Enhanced the codebase for better performance.
173175

174-
2.1: Fixed bugs (see https://github.com/shinsenter/defer.js/issues/82).
176+
2.1: Fixed bugs (see https://code.shin.company/defer.js/issues/82).
175177

176178
2.0: Upgraded to version 2 and renamed the plugin.
177179

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.0
1+
2.6.0

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
}
1313
],
1414
"support": {
15-
"issues": "https://github.com/shinsenter/defer.php/issues",
16-
"source": "https://github.com/shinsenter/defer.php"
15+
"issues": "https://code.shin.company/defer-wordpress/issues",
16+
"source": "https://code.shin.company/defer-wordpress"
1717
},
1818
"funding": [
1919
{
2020
"type": "github",
21-
"url": "https://github.com/shinsenter/defer.php/stargazers"
21+
"url": "https://code.shin.company/defer-wordpress/stargazers"
2222
},
2323
{
2424
"type": "paypal",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

defer-wordpress.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Plugin Name: A faster website! (aka defer.js)
2929
* Plugin URI: https://wordpress.org/plugins/shins-pageload-magic/
3030
* Description: 💯 Latest web technologies in website optimization by experienced web experts. 🔰 Very easy to use.
31-
* Version: 2.5.0
31+
* Version: 2.6.0
3232
* Author: Mai Nhut Tan
3333
* Author URI: https://code.shin.company/
3434
* License: GPL-2.0+
@@ -44,7 +44,7 @@
4444
if (!defined('DEFER_WP_PLUGIN_VERSION')) {
4545
define('DEFER_WP_PLUGIN_BASE', plugin_basename(__FILE__));
4646
define('DEFER_WP_PLUGIN_NAME', 'defer-wordpress');
47-
define('DEFER_WP_PLUGIN_VERSION', '2.5.0');
47+
define('DEFER_WP_PLUGIN_VERSION', '2.6.0');
4848
define('DEFER_WP_PLUGIN_PREFIX', DEFER_WP_PLUGIN_NAME . '_');
4949

5050
define('DEFER_WP_PLUGIN_HOOK', 'plugin_action_links_' . DEFER_WP_PLUGIN_BASE);
@@ -57,20 +57,20 @@
5757

5858
$has_deferjs = file_exists(__DIR__ . '/public/lib/defer_plus.min.js');
5959
define('DEFER_WP_SRC_DEFERJS_CDN', $has_deferjs
60-
? __DIR__ . '/public/lib/defer_plus.min.js'
61-
: 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.5.0/dist/defer_plus.min.js');
60+
? __DIR__ . '/public/lib/defer_plus.min.js'
61+
: 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.6.0/dist/defer_plus.min.js');
6262

6363
$has_polyfill = file_exists(__DIR__ . '/public/lib/polyfill.min.js');
6464
define('DEFER_WP_SRC_POLYFILL_CDN', $has_polyfill
65-
? plugin_dir_url(__FILE__) . 'public/lib/polyfill.min.js'
66-
: 'https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver');
65+
? plugin_dir_url(__FILE__) . 'public/lib/polyfill.min.js'
66+
: 'https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver');
6767

6868
define('DEFER_WP_HOMEPAGE', 'https://shinsenter.github.io/defer.js');
6969
define('DEFER_WP_PLUGIN_URL', 'https://wordpress.org/plugins/shins-pageload-magic/');
7070
define('DEFER_WP_PAYPAL', 'https://www.paypal.me/shinsenter');
7171
define('DEFER_WP_PATREON', 'https://www.patreon.com/appseeds');
7272
define('DEFER_WP_RATING', 'https://wordpress.org/support/plugin/shins-pageload-magic/reviews/?filter=5#new-post');
73-
define('DEFER_SOURCE_HOMEPAGE', 'https://github.com/shinsenter/defer.js');
73+
define('DEFER_SOURCE_HOMEPAGE', 'https://code.shin.company/defer.js');
7474

7575
require_once __DIR__ . '/vendor/autoload.php';
7676
}

includes/class-defer-wordpress.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function define_public_hooks()
218218
{
219219
$plugin_public = new Defer_Wordpress_Public($this->get_plugin_name(), $this->get_version());
220220

221-
if (!(defined('WP_CLI') && WP_CLI) && !is_admin() && !$this->is_wplogin()) {
221+
if (!(defined('WP_CLI') && WP_CLI) && !$this->is_ajax() && !is_admin() && !$this->is_wplogin()) {
222222
$this->loader->add_action('init', $plugin_public, 'init', -1);
223223
$this->loader->add_action('shutdown', $plugin_public, 'shutdown', 100000);
224224
}
@@ -234,8 +234,27 @@ private function is_wplogin()
234234
$incl_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, ABSPATH);
235235

236236
return (in_array($incl_path . 'wp-login.php', get_included_files())
237-
|| in_array($incl_path . 'wp-register.php', get_included_files()))
238-
|| (isset($_GLOBALS['pagenow']) && 'wp-login.php' === $GLOBALS['pagenow'])
239-
|| '/wp-login.php' == $_SERVER['PHP_SELF'];
237+
|| in_array($incl_path . 'wp-register.php', get_included_files()))
238+
|| (isset($_GLOBALS['pagenow']) && 'wp-login.php' === $GLOBALS['pagenow'])
239+
|| '/wp-login.php' == $_SERVER['PHP_SELF'];
240+
}
241+
242+
private function is_ajax()
243+
{
244+
if (
245+
!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
246+
&& 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])
247+
) {
248+
return true;
249+
}
250+
251+
if (
252+
empty($_SERVER['HTTP_ACCEPT'])
253+
|| false === strstr(strtolower($_SERVER['HTTP_ACCEPT']), 'html')
254+
) {
255+
return true;
256+
}
257+
258+
return false;
240259
}
241260
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "shinsenter/defer-wordpress",
33
"description": "🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the WordPress page.",
4-
"homepage": "https://github.com/shinsenter/defer-wordpress#readme",
4+
"homepage": "https://code.shin.company/defer-wordpress#readme",
55
"author": "Mai Nhut Tan <[email protected]>",
66
"license": "GPL-2.0",
77
"dependencies": {
88
"@shinsenter/defer.js": "^3.6.0"
99
},
1010
"repository": {
1111
"type": "git",
12-
"url": "git+https://github.com/shinsenter/defer-wordpress.git"
12+
"url": "git+https://code.shin.company/defer-wordpress.git"
1313
},
1414
"bugs": {
15-
"url": "https://github.com/shinsenter/defer-wordpress/issues"
15+
"url": "https://code.shin.company/defer-wordpress/issues"
1616
}
1717
}

0 commit comments

Comments
 (0)