Support » Plugin: Autoptimize » add js on scroll from top

  • Resolved evil


    Hi, i use your perfect plugin

    js is not important for my theme in first seconds.

    i load other javascript(external js) by scrolling(just 1px from top).
    this made my page speed great.
    but how can i do it for js that AO create.

    I’m sorry my English is poor

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


    you would have to hook into Autoptimize’s API to change the way the JS is loaded p47ri0t.

    so how have you implemented the loading-by-scrolling?

    Thread Starter evil


    @optimizingmatters i use this javascript code for static external js :

     function loadJS(file) {
        var jsElm = document.createElement("script");
        jsElm.type = "application/javascript";
        jsElm.src = file;
    var addsanjagha = false;
    function addsanjagh()
      if (addsanjagh === true) return;
       addsanjagha = true;
    function initSanjagh()
      if (addsanjagha === true) return;
    $(document).scroll(function() {
    • This reply was modified 3 years, 8 months ago by evil.
    Plugin Author Optimizing Matters


    hmm, not do-able in a couple of lines of code, but -assuming you’re OK writing some PHP- best would be to hook into the autoptimize_html_after_minify filter and using that to extract the last script tag (before </body>) which holds the link to the autopitimized JS, remove it from the HTML and add the JS instead?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add js on scroll from top’ is closed to new replies.