Hello,
We really like your pro plugin and have good luck with it on multiple sites on a WP 4.61 multisite network.
A number of page speed checkers keep giving us a low score because all the following resources seem to load on every page on the site even though we only use the PDF viewer shortcode on 1 or two pages.
Have you considered adding a configuration setting so users can enter the post, page or custom post type IDs where the PDF Viewer shortcode is used so that its resources will only load on the specific pages/posts identified by the user?
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery.lazyload/jquery.scrollstop.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery.lazyload/jquery.lazyload.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/hash.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/screenfull/dist/screenfull.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/turn.html4.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/turn.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/bxslider-4/dist/jquery.bxslider.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery-zoom/jquery.zoom.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/qtip2/jquery.qtip.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/magazine.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/isotope/dist/isotope.pkgd.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/posabsolute-jQuery-printPage-plugin/jquery.printPage.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/typeahead.js/dist/typeahead.bundle.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/grapnel/dist/grapnel.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/js/magazine.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/js/catalog.js
The author of the plugin WPFull Calendar employs this approach.
Upon initial activation the plugin resources load on every post and page so that everything will work regardless of which post or page the user inserts the shortcode in.
Later after the user has configured the posts or pages where they want to use WPFull Calendar, then the user can enter those post and page IDs in a user setting field and the plugin only loads its resources on those pages.
This seems like a very efficient solution that would require minimal plugin modification for PDF viewer to support.
Such a feature could help many users improve their page load speed on all pages where PDF view is not used and thus improve their Google scores.
Would you please consider adding such a feature to your plugin?
Until you do, how can I ONLY LOAD these resources on pages where PDF viewer shortcode is present?
Thank you for your assistance.
We really like your pro plugin and have good luck with it on multiple sites on a WP 4.61 multisite network.
A number of page speed checkers keep giving us a low score because all the following resources seem to load on every page on the site even though we only use the PDF viewer shortcode on 1 or two pages.
Have you considered adding a configuration setting so users can enter the post, page or custom post type IDs where the PDF Viewer shortcode is used so that its resources will only load on the specific pages/posts identified by the user?
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery.lazyload/jquery.scrollstop.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery.lazyload/jquery.lazyload.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/hash.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/screenfull/dist/screenfull.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/turn.html4.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/turn.js/turn.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/bxslider-4/dist/jquery.bxslider.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/jquery-zoom/jquery.zoom.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/bower_components/qtip2/jquery.qtip.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer/assets/js/magazine.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/isotope/dist/isotope.pkgd.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/posabsolute-jQuery-printPage-plugin/jquery.printPage.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/typeahead.js/dist/typeahead.bundle.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/bower_components/grapnel/dist/grapnel.min.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/js/magazine.js
http://soobahkdo.biz/wp-content/plugins/pdf-light-viewer-pro/assets/js/catalog.js
The author of the plugin WPFull Calendar employs this approach.
Upon initial activation the plugin resources load on every post and page so that everything will work regardless of which post or page the user inserts the shortcode in.
Later after the user has configured the posts or pages where they want to use WPFull Calendar, then the user can enter those post and page IDs in a user setting field and the plugin only loads its resources on those pages.
This seems like a very efficient solution that would require minimal plugin modification for PDF viewer to support.
Such a feature could help many users improve their page load speed on all pages where PDF view is not used and thus improve their Google scores.
Would you please consider adding such a feature to your plugin?
Until you do, how can I ONLY LOAD these resources on pages where PDF viewer shortcode is present?
Thank you for your assistance.
1 Answers
Hello SooBahkDo,
We improved assets handling in 1.3.11 version (should be released till the end of the week).
We didn’t add setting, instead there we have added conditions to include frontend assets on PDF single pages, PDF Archive, in cases, when current $post->post_content contains PDF Light viewer shortcodes.
And the last condition is a filter for customization, when you have our shortcode in widgets, etc. So you could add the following filter with any conditions in it (please note that in the example below I used php anonymous function which is not available in legacy versions):
We improved assets handling in 1.3.11 version (should be released till the end of the week).
We didn’t add setting, instead there we have added conditions to include frontend assets on PDF single pages, PDF Archive, in cases, when current $post->post_content contains PDF Light viewer shortcodes.
And the last condition is a filter for customization, when you have our shortcode in widgets, etc. So you could add the following filter with any conditions in it (please note that in the example below I used php anonymous function which is not available in legacy versions):
add_filter(PDF_LIGHT_VIEWER_PLUGIN.':should_enqueue_frontend_assets', function() { return true; });
It should be added before https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts hook is triggered.
Please login or Register to submit your answer
replied 8 years ago
Hello SooBahkDo,
Your post is good as always, thanks!
Yes, WPFull Calendar approach seems good to me so we will implement it.
For now you can add condition right in the code for this method https://github.com/antongorodezkiy/pdf-light-viewer/blob/master/controllers/AssetsController.php#L102
Something like this should work (code not tested):
global $wp_query;
$obj_id = is_home() ? '-1':$wp_query->get_queried_object_id();
if( empty($pdflv_scripts_limit) || in_array($obj_id, explode(',',$pdflv_scripts_limit)) ) {
// assets enqueue here
}