Title: Javascript Loads on Every Page
Last modified: January 11, 2018

---

# Javascript Loads on Every Page

 *  [Julie](https://wordpress.org/support/users/habannah/)
 * (@habannah)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/javascript-loads-on-every-page/)
 * Hi there,
 * Great plugin — I recently started using it and am very pleased with the results.
   Just a couple of requests and suggestions, though.
 * 1) Javascript loads on all pages, instead of only on pages where a form that 
   uses conditional logic is placed. Would it be possible to add a setting to choose
   where the conditional logic js loads? I imagine giving users the choice between
   an exclude or include condition would be the best option, since some people like
   myself will only want to include the logic on a few pages, while others might
   only want to exclude the logic on a few pages. I’m currently editing plugin files
   to control where the javascript loads by placing an is_page condition before 
   the call to enqueue_script, but obviously this isn’t ideal since I will have 
   to reinsert my changes every time the plugin updates. Here is my code:
 *     ```
       add_action('wpcf7_contact_form', 'wpcf7cf_enqueue_scripts', 10, 1);
       function wpcf7cf_enqueue_scripts(WPCF7_ContactForm $cf7form) {
           if (is_admin()) return;
           if ( is_page ( 'ID' ) ) {
           	wp_enqueue_script('wpcf7cf-scripts', plugins_url('js/wpcf7cfscripts.js', __FILE__), array('jquery'), WPCF7CF_VERSION, true);
           }
       }
       ```
   
 * 2) Also, you’ll notice that I changed the js file name, which leads to my second
   request of giving the file a unique name, instead of just scripts.js. In my experience,
   this can lead to problems if other plugins use the same file name. I may be wrong
   about that, but I figured it couldn’t hurt to bring it up…
 * 3) Lastly, I tried minifying the javascript, but the conditional fields all become
   visible and conditional logic stops working. I’m not sure if there would be a
   way to serve minified javascript that actually works? Right now I’m thinking 
   it doesn’t work because of the dependency on jquery, and from what I’ve seen 
   in the past, minified jquery never works, so I’m thinking this isn’t possible,
   but again, thought I may as well ask.
 * Thank you very much for your help with this!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fjavascript-loads-on-every-page%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * (@jules-colle)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/javascript-loads-on-every-page/#post-9875432)
 * Hi, I’m sorry to inform you that this is not very high on my priority list.
 * 1. It’s kind of important to load JS on every page, because people might load
   forms dynamically with ajax. Theoretically it’s possible to load JS files dyncamically
   during the ajax call, but it’s a lot of hassle, and I won’t bother as the file
   if pretty small and it will be cached anyway (so it will be downloaded only once
   to the client)
 * 2. No conflict possible here as the script will always be called in the full 
   path.
 * 3. You could try a caching plugin like w3 total cache or wp rocket to minify 
   all your javascript.

Viewing 1 replies (of 1 total)

The topic ‘Javascript Loads on Every Page’ is closed to new replies.

 * ![](https://ps.w.org/cf7-conditional-fields/assets/icon-256x256.png?rev=2072595)
 * [Conditional Fields for Contact Form 7](https://wordpress.org/plugins/cf7-conditional-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-conditional-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-conditional-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-conditional-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-conditional-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-conditional-fields/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jules Colle](https://wordpress.org/support/users/jules-colle/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/javascript-loads-on-every-page/#post-9875432)
 * Status: not resolved