Support » Plugin: Autoptimize » Disqus error

  • Resolved chatmandesign

    (@chatmandesign)


    I have both the Disqus comments plugin and Autoptimize installed. When I have Autoptimize enabled for JavaScript, Disqus fails.

    Disqus appears to add these scripts at the bottom of the page:

    <script type='text/javascript'>/*  */
    var embedVars = {"disqusConfig":{"platform":"wordpress@4.3.1","language":""},"disqusIdentifier":"3415 http:\/\/beaconathletics.com\/ballfields\/?p=3415","disqusShortname":"beaconathletics","disqusTitle":"NRPA 2015","disqusUrl":"http:\/\/ballfields.com\/2015\/10\/01\/nrpa-2015\/","options":{"manualSync":false},"postId":"3415"};
    /*  */</script> <script type='text/javascript' src='http://ballfields.com/wp-content/plugins/disqus-comment-system/media/js/disqus.js?ver=4.3.1'></script> <script type='text/javascript'>/*  */
    var countVars = {"disqusShortname":"beaconathletics"};
    /*  */</script> <script type='text/javascript' src='http://ballfields.com/wp-content/plugins/disqus-comment-system/media/js/count.js?ver=4.3.1'></script>

    When Autoptimize is enabled for JS, I only see the following:

    <script type='text/javascript' src='http://ballfields.com/wp-content/plugins/disqus-comment-system/media/js/disqus.js?ver=4.3.1'></script>

    And I get the following error in the console:

    Uncaught ReferenceError: embedVars is not defined

    It sounds to me like the problem is due to the in-line script that sets embedVars getting concatenated into the main scripts file. Unfortunately, since it’s in-line there is no filename to add to the exclusions list. Is there any way to prevent this script from being concatenated?

    Limiting Autoptimize to scripts in head, as I’ve seen suggested in response to similar questions, isn’t really a realistic workaround for me. In keeping with generally accepted best practices, nearly all of my scripts are referenced at the end of the body, so limiting Autoptimize to the head is not much better than disabling it entirely.

    If there’s not currently a solution for this, is it possible an option to exclude all in-line scripts could be added? I realize targeting specific ones would be extremely difficult, but it seems like only optimizing scripts loading from file, and ignoring in-line ones, should be relatively easy to implement.

    https://wordpress.org/plugins/autoptimize/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Frank Goossens

    (@futtta)

    Unfortunately, since it’s in-line there is no filename to add to the exclusions list. Is there any way to prevent this script from being concatenated?

    absolutely, as explained in the FAQ you can also exclude inline script by adding an “identifier string” to the exclusion list. in this case embedVars would be a good candidate.

    If there’s not currently a solution for this, is it possible an option to exclude all in-line scripts could be added?

    this will become available as an option in the next AO (replacing “look only in head”). until then you can accomplish this with a couple of lines of code (adding it to WordPress using e.g. code snippets):

    add_filter('autoptimize_js_include_inline','support_ao_js_include_inline',10,1);
    function support_ao_js_include_inline() {
            return false;
    }

    hope this helps,
    frank

    Thread Starter chatmandesign

    (@chatmandesign)

    Ah, perfect! The description on that field implies it has to be a filename, so I didn’t realize this was an option. Thanks so much!

    Thread Starter chatmandesign

    (@chatmandesign)

    Resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disqus error’ is closed to new replies.