Closed foliovision closed 6 years ago
This is not a good solution. What if the user insert the PHP code of the poll manually onto a page or someone is using the sidebar widget for the poll? All of this doesn't use the shortcode
Hello Lester,
thank you for the reply. You are right about these cases, but why affect page speed for rest of the users who user the plugin in a standard way?
The global $poll_shortcode_used
could be moved to the PHP function directly of course.
The CSS could be loaded in footer (not recommended, but better than loading it all the time) using the same logic as JS.
Or you could just use what we created and add a "Load everywhere" option for the plugin which would be intended for these users who play with PHP code and can't rely on this dependency check which we crated.
Thanks, Martin
Hmm define standard? The standard way is to use it on the sidebar not in the post. The plugin was designed to be that and I have more users putting it in the sidebar then in the post based on the forum support sites that I visited.
I would prefer you to deregister the JS/CSS and copy the generated CSS and JS and put it inside your own theme CSS/JS. That is what I did to my own site.
So it could be reworked to work with the PHP function easily and also preferably CSS in the footer.
Moving the CSS and JS to the theme doesn't shound like a fix to me - since if there is an update in the CSS/JS I would have to be copying over your new files.
Wouldn't you prefer if the plugins worked the way we outlined here? You attached some article about why it should work this way in the Issue yourself: https://github.com/lesterchan/wp-polls/issues/45
That was two years ago. I think there is a better solution like register the CSS/JS then when the get_poll function is called, call the enqueue script.
Something along the line.
These practices are still the best, even though it's 2 years old.
I had a look at get_poll(), noticed it uses global $polls_loaded
and re-coded the CSS and JS enqueueing based on that.
Now it only loads the JS and CSS if there is some poll, so it all goes into footer. If the poll is in a post it works, if it's in a widget, it works as well. Yet our homepage stays clean with reduced amount of requests.
Thanks, Martin
I am ok putting
if( empty( $polls_loaded ) ) {
return;
}
in function poll_scripts()
But I don't like the idea of putting CSS at the footer, the specs for HTML5 states that tag is suppose to be in the header. Unless you can proof me wrong https://developer.mozilla.org/en/docs/Web/HTML/Element/link
Hello Lester,
you are right about the CSS. So it could be checking global $posts
as well as all the active widgets for any WP Polls instance and load the CSS in such case.
Thanks, Martin
45 We created this fix.