-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assets loaded on all pages #135
Comments
I agree on the fact that the plugin assets should be loaded only if required. Though, I have two questions/remarks regarding how this should be achieved by a WordPress plugin:
|
The MathJax-LaTex plugin has solved the problem this way:
|
Here's a rough attempt at this: This hasn't been run/tested. |
It seems that the constraint to have Though, I'm still concerned with AJAX-based themes. |
@paulschreiber Sorry for the long delay in replying. It seems that it is now possible to have a more straightforward approach, as describe in: http://scribu.net/wordpress/conditional-script-loading-revisited.html I'll refactor the code of the plugin to follow this pattern, but I've no time for the moment. |
That blog post is from 2013. I think the strategy I employ above is simpler. |
@yo35 Can you take a look at this? |
Hi. This is done for the front end in version 5.5 (just released). Additional refactoring must be done beforehand for the back end. |
Thanks! |
I see this was reverted. Please try the method I suggested. |
It has been reverted for CSS, because it seems to be incompatible with some themes (although it appears to work with most of them) : see #145. The solution you proposed in 784f65f does not work (whatever the theme), because the |
Can you work on a fix for this you like? It's adding uncompressed CSS to all sorts of pages, even when the chess content isn't present. This check catches some of the cases: <?php
function rpbchessboard_init_js_css() {
if ( ! is_single() ) {
return;
} |
@paulschreiber Your approach consisting in not inserting CSS/JS if |
As of version 5.7 (just released), I've re-introduced lazy-loading of CSS assets on frontend, although it is still not clear whether this approach is the right approach. An option is provided in the "settings" page to fallback to the "always-enqueue-CSS-and-JS strategy" if any problem is encountered with. And there WILL be issues with some themes such as the one used in #145 , or plugins such as bbPress (see #65). I'm quite surprised I cannot find any proper directives of the WP architects on how to solve this issue. The use-case "provide a custom shortcode that needs specific CSS/JS to be rendered property, and ensure those CSS/JS are enqueued only on the pages with this custom shortcode" seems quite common among the WP plugins though... |
The assets (inline CSS, CSS, JS) are loaded on every page.
On the front end, should only be loaded on pages where the shortcodes (
[pgn]
,[fen]
, etc.) are present.On the backend, they should only be loaded on post-new.php and edit.php.
The text was updated successfully, but these errors were encountered: