locked
javascript reference RRS feed

  • Question

  • User1109483674 posted
    If we use a master.page, is wrong to put the javascript reference inside the <head> or it is better to put it at the end of the <body>

    For example:

    <head runat="server">

    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=11;IE=10;IE=9;IE=8;IE=7;IE=edge;Chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <!-- CSS -->


    <link href="Content/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="Content/jquery-ui-1.11.4.custom/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="Content/css/bootstrap.min.css" rel="stylesheet" />
    <link href="Content/hint.css-2.5.0/hint.min.css" rel="stylesheet" />
    <link href="Content/Aduana.css" rel="stylesheet" />

    <script src="../Scripts/jquery-1.9.1.js"></script>
    <script src="../Content/jquery-ui-1.11.4.custom/jquery-ui.js"></script>
    <script src="../Scripts/Funciones.js"></script>

    <!-- JS -->
    <script src="../Script/jquery-3.2.1.min.js"></script>
    <script src="../Script/bootstrap.min.js"></script>
    <script src="../Scripts/jquery.timepicker.min.js"></script>



    <!-- para la clase collapsible panel -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



    <title>Sistema Fiscalización de Trámites Aduaneros</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    </head>
    Friday, June 15, 2018 7:54 PM

All replies

  • User-369506445 posted

    Hi

    By putting JavaScript at the bottom of the page, our pages will appear to be loading twice as fast.

    When you put your JavaScript at the top of the page, the browser will start loading your JS files before the markup, images and text. And since browsers load JavaScript synchronously, nothing else will load while the JavaScript is loading. So there will be a timeframe of a few seconds where the user will see a blank page, while the JavaScript is loading.

    On the other hand, if you place your JavaScript at the bottom of the page, the user will see the page loading first, and after that the JavaScript will load in the background. So if for example your CSS & HTML takes 5 seconds to load, and your JavaScript takes another 5 seconds, putting our JavaScript on the top of the page will give the user a “perceived” loading time of 10 seconds, and putting it on the bottom will give a “perceived” loading time of 5 seconds.

    Friday, June 15, 2018 8:07 PM
  • User36583972 posted

    Hi Fredy511,

    If we use a master.page, is wrong to put the javascript reference inside the <head> or it is better to put it at the end of the <body>

    The following articles give some suggestion about Using JavaScript with Master Pages in ASP.Net. We can handle it in different circumstances. Hope it will help you.

    Using JavaScript with Master Pages in ASP.Net
    https://www.aspsnippets.com/Articles/Using-JavaScript-with-Master-Pages-in-ASP.Net.aspx

    Dynamically Adding JavaScript To Your ASP.NET Master Page From A Child Page
    https://www.dougv.com/2010/02/dynamically-adding-javascript-to-your-asp-net-master-page-from-a-child-page/

    Best Regards,

    Yong Lu

    Monday, June 18, 2018 8:03 AM