I found three connected scripts in the header and in the basement, each of which makes an http request. I decided to combine them into one file. As a result, the 2nd and 3rd scripts refuse to work.

Question: Tell me how to combine three javascript in one file to reduce http-requests?

Javascript files

1 script Site menu

function( $ ) { // меню var body = $( 'body' ), _window = $( window ); function() { var nav = $( '#primary-navigation, #secondary-navigation' ), button, menu; if ( ! nav ) { return; } button = nav.find( 'h1.menu-toggle, h2.menu-toggle' ); if ( ! button ) { return; } menu = nav.find( '.nav-menu' ); if ( ! menu || ! menu.children().length ) { button.hide(); return; } $( 'h1.menu-toggle' ).on( 'click.pixelcom', function() { nav.toggleClass( 'toggled-on' ); } ); $( 'h2.menu-toggle' ).on( 'click.pixelcom', function() { nav.toggleClass( 'toggled-oncat' ); } ); } } 

2 script - Show hide div block

 function look(type){ // скрыть показать param=document.getElementById(type); if(param.style.display == "none") param.style.display = "block"; else param.style.display = "none" } 

3rd script Up to page header

 function dd_scrolltotop(duration){// вверх duration = duration || 500 var rootel = (document.compatMode =="BackCompat")? document.body : document.documentElement if (rootel.scrollTop == 0) rootel = document.body var curscrolltop = rootel.scrollTop, scrolltimer, elapsedtime, starttime = new Date().getTime(), animatedegree = 0 var totaldis = curscrolltop clearTimeout(scrolltimer) function jumptop(){ elapsedtime = new Date().getTime() - starttime if (elapsedtime < duration){ rootel.scrollTop = totaldis - (totaldis * (1-Math.cos((elapsedtime/duration)*Math.PI)) / 2) scrolltimer = setTimeout(function(){jumptop()}, 10) } } jumptop() } 
  • Console open? What kind of errors does it display? - fremail
  • Yes, like this character} swears - Viher

1 answer 1

Apparently, you lose when copying} or, on the contrary, you attribute extra. In these three pieces, the number of opening and closing curly brackets is the same.
I would recommend stamping; in the last script, because JS does not always come up with this, and if the lines are glued together - the code becomes just a text. And I would rewrite the code already in Jquery, since you connect it. It would be much shorter :)

  • Disabled jQuery completely, the menu will do on pure js. fremail ATP - Viher