• Resolved macitemre

    (@macitemre)


    as mentioned in the topic : https://ww.wp.xz.cn/support/topic/some-inline-javascript-not-being-deferred/ i have a different cause detected. My inline js is somehow have comments inside. But these comments are html comments like <!– –>. This was my situation, autoptimize replaces the comment <!– bla bla.. –> with some comment code %%COMMENTS531ab… then try to replace the code with deferred base64 but, the str replace inside autoptimizeScripts.php code : $this->content = str_replace( $tag, $new_tag, $this->content ); cannot replace code, as the comment in the code has replaced the comment with %%Comment but it cannot so.

    That was my problem. i know we shouldn’t use html comment inside script, but the code is beyond too old.

    Maybe you want to fix this situation or not.

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    sure I’ll have a look, can you provide me with the exact code snippet that causes this behavior, I’ll use that to test!

    best,
    frank

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    evening @macitemre , would be great if you could an example JS code snippet which triggers this bug πŸ™‚

    Thread Starter macitemre

    (@macitemre)

    as i mentioned, if you write an inline javascript code in your post or something; put HTML comments inside somewhere, (mine’s come from a very old db that has very silly content inside the posts) . That triggers it. I don’t know that you should solve this, but, that is the case.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    so something like this?

    <script>
    <!--
    console.log('bug');
    -->
    </script>
    Thread Starter macitemre

    (@macitemre)

    yes exactly

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    a bit of an edge case indeed, but I’ll have a look πŸ™‚

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, can you give this a try;

    in autoptimizeScripts.php on line 463 change

    $this->content = str_replace( $tag, $new_tag, $this->content );

    into

    $this->content = str_replace( $this->hide_comments( $tag ), $new_tag, $this->content );

    this seems to do the trick for me and it seems a pretty harmless fix so if confirmed working and assuming this does not cause regressions, I might add this to a next version of AO πŸ™‚

    Thread Starter macitemre

    (@macitemre)

    i hope somebody not use a js variable like

    var a = ‘<!– bla –>’;

    πŸ™‚

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    it *looks* like that might not be a problem? πŸ˜‰

    View post on imgur.com

    Thread Starter macitemre

    (@macitemre)

    congratz :), and thanks by the way, for your attention

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘autoptimize does not defer inline js with comments’ is closed to new replies.