PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Scripts in the footer

  1. I see some others requesting scripts in the footer in this forum, but I don't see this concern taken too seriously in the responses. It's fairly well established that this is important for site performance. Also, in my case Gravity Forms breaks my script minification because the plugin doesn't behave as Wordpress recommends. Out of 30 or so plugins that I run on our site, this is the only one that I have been unable to get into the footer. So, after reading the code and seeing how you use inline JS and various snippets of JS in <head>, I hope that you realize this causes headaches downstream. You could accomplish all that you're doing and be making better use of wp_enqueue_script and wp_localize_script to separate the JS from <head> and DOM elements in future releases. It would certainly help developers who expect plugins to behave in a certain way--and I imagine it would help your development process as well. Thanks for considering this!

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  2. Richard Vav
    Administrator

    If you check the documentation there is a function for loading the scripts in the footer instead of the head, http://www.gravityhelp.com/documentation/page/Gform_init_scripts_footer

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  3. Thanks for the response, I was not aware of this filter.

    Even after applying, I still have the conditional_logic.js script loading in the head. Looking at the wp_enqueue_script code for this asset, it appears to be hard-coded to output in the head. So, without looking into Gform_init_scripts_footer filter too much, I don't know how this would put conditional_logic.js in the footer. Then naturally, its dependencies put gravityforms.js and jquery.js into the head as well. So, no luck there.

    Even if we got that far, it doesn't appear that jQuery can be in the footer, due to the Javascript snippets PHP outputs throughout the page. Correct me if I'm wrong, but your plugin doesn't allow jQuery in the footer.

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  4. David Peralty

    That's correct. JQuery needs to be in the header for Gravity Forms to work.

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  5. OK, thanks for confirming this.

    I guess the purpose of my post is to point out that this (unpublished?) requirement of Gravity Forms causes headaches for developers downstream. I hope that you would consider rewriting how Javascript is enqueued and localized so that it doesn't pollute the DOM in future releases of Gravity Forms. Wordpress makes this process very easy, thankfully. Thanks for listening!

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  6. David Peralty

    This change is already in progress. All my best!

    Posted 11 years ago on Friday December 7, 2012 | Permalink