• Resolved christian70

    (@christian70)


    Hi, the plugin is impressive, great loading speed improvement. But I’ve got this problem on my site: I use a function in my WordPress functions.php that loads some code on the site only if a certain condition is true, something like:
    if (condition) { code }.

    The problem is that serving the cached pages, this function doesn’t work properly anytime, and the code is served into the pages most of times despite of the condition.
    Obviously it works fine when I’m logged in and the pages are not cached.

    Is there anyway to make that function work along with SG plugin? It’s driving me nuts.

    Thanks a lot.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter christian70

    (@christian70)

    By the way, the same occurs when I load the Js script conditionally from functions.php:
    if (condition) { enqueue script }

    I do need the script to be loaded only if the condition is true.
    How could I do that?

    Thanks.

    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    I am afraid that you will experience this problem with any full-page caching that you utilize on your site. I would advice to use the exclude functionality and remove that page from the dynamic cache.

    Thread Starter christian70

    (@christian70)

    Hi, to be honest I don’t get that problem with other cache plugins (i.e. cache enabler or cachify).

    I can’t deactivate cache option for all pages obviously.

    The fact is that I can’t understand how the functions and the hooks used in functions.php are cached by SG plugin, and there’s no way to cache the static contents of pages and let functions.php do its job.

    I fix my problem with a simple trick (but I’m not sure it’s a good practice, even if it works): in my pages I load a new Js file XXX in which via Jquery I load the external script YYY I need at certain conditions (cookies accepted), and excluded XXX file (and only that file path) from caching.

    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    That sounds like browser caching of your JS files. If they are so dynamic, you can add a timestamp to their names so they are unique each load.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to load scripts dynamically’ is closed to new replies.