Should scripts be included in the head in case of webapp?

Several years ago, I learned that <script>in the <head> block page is displayed by reducing the loading time of web site, instead they should be included in the end <body>.

I think this does not apply to webapp, which does not work without JavaScript anyway . In fact, it should even be advisable to download them first due to the compilation of the templates. However, in all the Ember and Angular tutorials, I see that the scripts are included at the end. Is that still reasonable?

+4
source share
6 answers

As for angular, most of the time it makes very few differences when you put them. In most cases, angular web applications will have an incredibly small start page. Most of your actual functions will be added later via view or ui-view (if you use angular ui).

Angular also includes the ng-cloak directive , which will hide your application until the templates are compiled and displayed. This is a good way to hide the template syntax from the end user until ready.

On the topic of posting scripts, the official documentation on angular says:

script . script , HTML angular.js script. http://docs.angularjs.org/guide/bootstrap

, ( jQuery, ..), , . , . : HTTP-.

, , Grunt, .

+13

<head>. $.ajax, , , DOM . , webapp (, JSON), $.getJSON() head .

, , head . , .

+4

script :

  • : , .
  • After Body: DOM, .

:

- , , .

DOM- , , , DOM .

ng-cloak , DOM . , , - .

+4

. , , , async. , . , , , . . , , .

+3

" js " - . .

  • , , . .

  • . MBPS. 100 200 . JS

    .

: , :)

+1

Google PageSpeed ​​checker ( http://developers.google.com/speed/pagespeed/insights/ ) wants the scripts to be placed at the end. And it’s more expensive when you also focus on mobile devices. Therefore, even if the page requires js to work better, to load it at the bottom. First, the static page loads and gives the user an idea of ​​the content. And after that you will create it using your scripts.

-one
source

All Articles