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

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

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


  
    

        
7条回答
  •  死守一世寂寞
    2021-02-15 13:20

    If you don't have full server access and can't turn on gzip encoding then it's pretty useful to put the following in your javascript file (note: will need to be renamed to file.js.php or parsed as PHP through .htaccess directive):

    
    // put all your regular javascript below...
    

    You could also use it for better cache control, visitor tracking, etc in lieu of server-controlled solutions.

提交回复
热议问题