admin管理员组

文章数量:1292148

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

I want to know which is first to load or execute.

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

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

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

I want to know which is first to load or execute.

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

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

Share Improve this question edited Jun 8, 2016 at 11:49 GottZ 4,9471 gold badge37 silver badges47 bronze badges asked Jun 4, 2012 at 6:55 prakashprakash 1842 silver badges10 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 16

Pragmatically speaking, this is the typical order:

  • PHP runs first and constructs the page.
  • The browser loads the resulting HTML (any JavaScript found gets executed immediately)
  • Any JavaScript that was tied to the DOM ready or load event gets executed once the whole HTML is read and all objects are loaded respectively.

PHP will execute first, then HTML and finally javascript.

  • You send request to server, server executes your script
  • Then returns rendered html to browser, browser parses HTML(inline javascript executed)
  • Finally executes external included javascript files, one by one in order they are included.

本文标签: phpHTMLJavascript execution orderStack Overflow