PHP, HTML, Javascript execution order

I have a test.php file and this file contains some PHP code, HTML elements and some internal JavaScript and some external JavaScript.

I want to know what to download or execute first.

PHP or HTML or JavaScript? I want to know the execution order.

Your answers are greatly appreciated and very helpful to me and to others.

+8
javascript html php
source share
2 answers

Pragmatically, this is a typical order:

  • First, PHP starts and builds the page.
  • The browser loads the received HTML code (any JavaScript found is executed immediately)
  • Any JavaScript bound to the DOM ready or load event is triggered after reading all the HTML and loading all the objects, respectively.
+7
source share

PHP will execute first, then HTML, and finally javascript.

  • You send a request to the server, the server executes your script
  • Then it returns the displayed html to the browser, the browser parses HTML (embedded javascript)
  • Finally, external javascript executables are included in turn to be included.
+3
source share

All Articles