最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PHP, HTML, Javascript execution order - Stack Overflow

programmeradmin15浏览0评论

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.
发布评论

评论列表(0)

  1. 暂无评论