• Hi, I am using the same plugins, including WordPress Popular Posts with Merge + Minify + Refresh plugin, since I started the site. When I disable Merge + Minify + Refresh, the WordPress Popular Posts widget works normally. Please help.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter templederr

    (@celebtemple)

    Hi, I have added WordPress Popular plugin in “Ignore these files (one per line):”, please fix this in upcoming update because this plugin was worked perfectly before Merge + Minify + Refresh the latest update.

    https://www.my-domain.com/wp-content/plugins/wordpress-popular-posts/assets/js/wpp.js
    https://www.my-domain.com/wp-content/plugins/wordpress-popular-posts/assets/js/wpp-5.2.1.min.js
    https://www.my-domain.com/wp-content/plugins/wordpress-popular-posts/assets/js/wpp.min.js

    Thanks.

    Hi there,

    I’m the developer of the WordPress Popular Posts plugin.

    To explain better the situation: WordPress Popular Posts version 5.2 injects a application/json script into the <head> section of the page that contains a JSON string, for example:

    <script type="application/json" id="wpp-json">
    {"sampling_active":0,"sampling_rate":"100","ajax_url":"https:\/\/www.example.com\/wp-json\/wordpress-popular-posts\/v1\/popular-posts","ID":false,"token":"a787dd82b4","lang":null,"debug":true}
    </script>

    When this plugin is active, this inline application/json script is apparently bundled with the rest of the minified code (or removed altogether from the page), breaking WordPress Popular Posts’ ability to track pageviews, display widgets, etc.

    application/json script tags should be safe to exclude from the JS minification/bundling process as the browser doesn’t execute them (they’re just JSON strings) and they won’t load (external) JS files either.

    Other solutions I tested (like Autoptimize) do seem to leave these <script type="application/json">...</script> tags alone so I’m hoping you could implement this as well in your plugin for better compatibility with WPP and other plugins using <script type="application/json">...</script> tags.

    If you have any questions don’t hesitate to reach out.

    Thanks in advance!

    • This reply was modified 4 years, 8 months ago by Hector Cabrera. Reason: Fixed script tag
    Plugin Author launchinteractive

    (@launchinteractive)

    Thanks for providing that extra information Hector. I’ve had a read through the WordPress Popular Posts code and I’m not sure there is a way we can detect that you are going to modify the script tag.

    A potential workaround is adding the wpp-js script file to the MMR ignore list eg. https://DOMAIN.COM/wp-content/plugins/wordpress-popular-posts/assets/js/wpp-5.2.1.min.js
    I’m not entirely happy with this as the user needs to know to do this and will need to do it every time your javascript file path changes.

    Is there any reason you can’t output your json file using the wp_head action?

    The JSON object is a dependency of WPP’s JS file so it needs to be loaded first. I’m not sure it’s possible to make sure that happens in a reliable way by hooking into wp_head. Using the wp_add_inline_script() function (introduced with WordPress 4.5) does ensure the loading order is exactly as expected, hence the reason why WPP doesn’t use the wp_head hook.

    Autoptimize apparently does check whether there are any application/json script on the page and if so they’re excluded from the JS minification (as I mentioned before). WPP 5.2 works normally with it.

    • This reply was modified 4 years, 8 months ago by Hector Cabrera. Reason: Improved wording for clarity
    • This reply was modified 4 years, 8 months ago by Hector Cabrera.
    • This reply was modified 4 years, 8 months ago by Hector Cabrera.
    Plugin Author launchinteractive

    (@launchinteractive)

    I haven’t looked into the way Autoptimize works but I suspect it is different to MMR. MMR bundles enqueued scripts and can’t see the script tags to check if they are application/json.

    I think we should change our code to handle wp_add_inline_script better but it doesn’t look like your using it. Am I missing something?

    I think we should change our code to handle wp_add_inline_script better but it doesn’t look like your using it. Am I missing something?

    It’s here ??

    Plugin Author launchinteractive

    (@launchinteractive)

    Thanks Héctor, I was looking at the previous version of the code. I’ve been trying to think of a way that we could make this work and I haven’t come up with a good solution. The reason is that MMR changes the enqueue handles so your convert_inline_js_into_json function won’t do anything. What could work is if your function is changed from checking the handle to checking the $src. Do you think that would be an option?

    Not sure, I’d have to try and see. Will do once I get some spare time, I’ll keep you guys posted.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WordPress Popular Posts not working after latest update’ is closed to new replies.