Error in including .js file in wordpress theme

0

I included a .js file in the header.php of my theme using the wordpress control panel.

However, the line I inserted into the file does not appear on the page when I check the source code.

I'm doing this:

Wordpress panel > Appearance > Editor > header.php >

<script type="text/javascript" src="https://protegex.italorodrigo.com.br/contato/municipios.js"></script>

Butit'sasifIhavenotdoneanything...

Includetheabovelinebetweenheadtags.

Any tips?

    
asked by anonymous 07.06.2018 / 02:22

1 answer

1

I think the "problem" is partly in Rocket's use ( link ), which is a plugin for caching and optimizing scripts injected into the page

As you can read in their feautures:

  • link it concatenates the injected scripts and minifies the page

    / li>

  • link puts all scripts to load as defer

In other words, because of defer will only be processed when the page loads, but in the middle of your site has loose scripts like this on line 29 and 30:

<script type="text/javascript">var ajaxRevslider;

            jQuery(document).ready(function() {
                // CUSTOM AJAX CONTENT LOADING FUNCTION

As Rocket can only optimize scripts that are in .js files, then this loose script will not be optimized and due to the use of defer the script will not be processed, ie it would be better if this script were moved to a file .js

So to conclude, this is why even when writing this:

 <script type="text/javascript" src="https://protegex.italorodrigo.com.br/contato/municipios.js"></script>

Youseethis:

<scripttype='text/javascript'src='https://protegex.italorodrigo.com.br/wp-content/cache/busting/1/wp-includes-js-jquery-jquery-1.12.4.js'></script><scriptsrc="//use.typekit.net/e590690a5a7eb8cf5aba4f1e0fc6a9be49cb81a2.js" defer></script>

<script src="https://protegex.italorodrigo.com.br/wp-content/plugins/wp-rocket/min/?f=/contato/municipios.js,/contato/municipios.js,/wp-includes/js/jquery/jquery-migrate.min.js,/wp-includes/js/jquery/ui/core.min.js,/wp-content/plugins/mega-addons-for-visual-composer/js/script.js,/wp-content/plugins/essential-grid/public/assets/js/lightbox.js,/wp-content/plugins/essential-grid/public/assets/js/jquery.themepunch.tools.min.js,/wp-content/plugins/revslider/public/assets/js/jquery.themepunch.revolution.min.js,/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js,/wp-content/plugins/js_composer/assets/js/vendors/woocommerce-add-to-cart.js,/wp-content/plugins/testimonial-rotator/js/jquery.cycletwo.js,/wp-content/plugins/testimonial-rotator/js/jquery.cycletwo.addons.js,/wp-content/themes/easyweb/js/jquery.plugins.js"data-minify="1" defer></script>

Another thing, probably municipios.js should be the last, after the jQuery add-ons and plugins, if such municipios.js depend on jQuery, of course.

Read about defer and async

10.06.2018 / 01:26