What are the advantages to putting your Javascript in a .php file?

前端 未结 7 2497
独厮守ぢ
独厮守ぢ 2021-02-15 12:40

I occasionally come across pages where some Javascript is included via a PHP file:


  
    

        
7条回答
  •  眼角桃花
    2021-02-15 13:27

    There's no benefit for the example you gave above (beyond peculiar deployment scenarios where you have access to .php files and not .js files, which would be insane but not unheard of).

    That said, this approach allows you to pass the JS through the php parser - which means you can generate your JS dynamically based on server variables.

提交回复
热议问题