• If I use cache plugins (like WP-Rocket) that has option to load JS files ‘deferred’, the EnlighterJS doesn’t work, returning error: ‘EnlighterJS resources not loaded yet’.

    You should wrap the JS code you add to the page in some sort of load waiting code to execute when all the JS files are loaded, because when deferred loading is active, your code embedded in HTML is executing before the files are loaded.

    Milan

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Andi Dittrich

    (@andi-dittrich)

    Hi @gdragon

    please read the faq: https://github.com/EnlighterJS/documentation/blob/master/wordpress/FAQ.md#javascript-error-enlighterjs-resources-not-loaded-yet

    the defer/async attributes should NEVER be used for third party resources…it’s a common issue with optimization plugins in WordPress because most users didn’t know about the side effects of these options

    just exclude all EnlighterJS resources from “optimizations”

    Thread Starter Milan Petrovic

    (@gdragon)

    This is simply not true.

    The code that uses JS that is deferred just needs to be wrapped into the onLoad code (jQuery or VanilaJS): https://youmightnotneedjquery.com/#ready and it doesn’t cause any issues, and JS file can be deferred and the code that depends on it is executed when the document is ready. Only critical files should be loaded without deferred (like jQuery core), and the syntax highlight code is far from critical for the page preparation.

    So, your plugin JavaScript that is added into the footer of the page needs to be wrapped in onLoad code.

    A lot of plugins do this and work fine, yours is the only plugin I use that fails because of the optimization.

    And I use pure JS version of EnlighterJS already for some projects and manually used wrap code and it worked fine. As for your WordPress plugin, this problem started after 4.0 update, before it was fine with the deferred loading.

    Regards,
    Milan

    Plugin Author Andi Dittrich

    (@andi-dittrich)

    Milan,

    sorry you’re partial wrong..please take a deeper look into MDN docs regarding defer and async – it’s not as easy as it might look..

    your method using jQuerys ready event (similar/same as vanilla DOMContentLoaded) work only as expected with the defer attribute.

    async will completely decouple the javascript loading/execution of any page events – this means it may work with the ready event but this is not guaranteed – and that’s the real issue.

    the only workaround is to move the initialization code to the external library itself (like the EnlighterJS css files). but the big disadvantage is that every change to the plugin settings will enforce the browser the reload the whole javascript file.

    adding a named function wrapper to the initialization code which is triggered by the external library might be an solution….but there are also some “optimization” plugins which altering the header/footer/priority invocation of the scripts and there will may some conditions where it didn’t work.

    if you have any better idea how to deal with async/defer i can implement it – but this solution has to be bulletproof

    best regards, Andi

    Plugin Author Andi Dittrich

    (@andi-dittrich)

    Dear Milan,

    v4.3 includes an option to merge the library with the configuration into a single file – this works with defer and async (Enlighter -> Options -> Resources -> Initialization -> “single file”) .

    see https://github.com/EnlighterJS/Plugin.WordPress/commit/9ec0ac24a86000e1a7617433b8a257730b1ec51c

    i appreciate your feedback

    Thread Starter Milan Petrovic

    (@gdragon)

    This is great solution, thanks!

    Greetings, everyone

    sorry for the inconvenience, as this topic matters, i tried posting it on GDbbpress tool support but it would not pass moderation.

    please can somebody advised how to properly use this shortcode as i tried it but registered members, even participant, they cannot see the hidden content, i know the have to replied to the posts or topic to see but still after they replied still the hidden content not showing

    shortcode im having problem with is [hide hide=”reply”]{content}[/hide]

    Does this shortcode works only for bbpress ?
    Cuz i have asgaros forum plugin installed, theme is Oceanwp and yes i also have bbpress, buddypress installed.

    Regards.

    Glad you’ve addressed this issue – is there a reason that 4.3 isn’t available from the Repo yet, but only on Github?

    Plugin Author Andi Dittrich

    (@andi-dittrich)

    please don’t take over old threads.

    v4.3 is not available on GitHub..only the dev/master branch is available containing the 4.3-beta version identifier

    Sorry, I thought you’d prefer I add the question here rather than start a new thread for it, since it’s on the same exact topic.

    I’m also kind of confused now about what is and isn’t supposed to be in distribution. I’ve added the 4.3 Beta WordPress plugin to my site, after downloading it all from Github, and it seems to be working fine, even if it’s not quite right – in the sense of having unneeded files and not being in accordance with your expectations, apparently.

    You’ve got a lot going on over there on Github, and you have a very fine plugin. I’m just trying to keep my site up to date and well-optimized, and to continue to use your plugin, which recently started producing the error and ceasing to function for me, and it’s only today that I had the time to investigate further.

    • This reply was modified 4 years, 4 months ago by CK MacLeod.
    Plugin Author Andi Dittrich

    (@andi-dittrich)

    the official release are available on GitHib (https://github.com/EnlighterJS/Plugin.WordPress/releases) and also published to WordPress registry.

    OK but up above there you were describing the 4.3 release addressing the problem addressed on this thread. The latest official release is 4.2, which doesn’t, as far as I’ve seen, address the problem. How are you recommending that we deal with the issue?

    • This reply was modified 4 years, 4 months ago by CK MacLeod.
    Plugin Author Andi Dittrich

    (@andi-dittrich)

    exclude the EnlighterJS resources from being altered (async/defer) attributes

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘EnlighterJS resources not loaded yet’ is closed to new replies.