javascript - Jquery elements only work after page refresh -


i building reacts based application, have few jquery elements on page such jqueryui date picker , bootstraps tooltip.

the problem these elects not work until reload page.

so jquery scripts not loaded first time around.

i have looked through console , cannot see errors related jquery/javascript.

any appreciated. here index.html page

<!doctype html> <html class="no-js" lang="">   <head>       <meta charset="utf-8">       <meta http-equiv="x-ua-compatible" content="ie=edge">       <meta name="description" content="">       <meta name="viewport" content="width=device-width">        <title>icetea</title>        <!-- latest compiled , minified javascript -->       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>        <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>        <!-- jquery ui js - used datepicker -->       <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>        <!-- bootstrap theme -->       <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">        <link rel="stylesheet" href="/css/main.css">       <!-- jquery ui css - theme: blitzer, used datepicker -->       <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/blitzer/jquery-ui.css">    </head>   <body>      <div id="app"></div>      <script src="/js/main.js"></script>      <script>       $(document).ready(function(){           $('[data-toggle="tooltip"]').tooltip();       });     </script>      <script>       $(function() {         $( "#datepicker" ).datepicker();         $( "#datepicker" ).change(function() {           $( "#datepicker" ).datepicker( "option", "dateformat", "dd d mm" );         });       });     </script>    </body> </html> 

what's happening initial page load attempts load network, while second load retrieves assets browser cache. verify using developer tools load without cache; if hypothesis correct, see higher prevalence of errors, when reload page.

as @vanburen pointed out in comment, explanation you're not ordering scripts correctly. jquery should loaded first, right you've got after bootstrap. supported console error you'll see when attempt load page as-is developer tools open:

uncaught error: bootstrap's javascript requires jquery(anonymous function) @ bootstrap.min.js:6

as additional optimization, can consider putting css before synchronous scripts, browser can loading , parsing them while it's simultaneously loading javascript.

bottom line: sure familiar developer tools. should first resource when face unexpected behavior.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -