javascript - Is it not feasible to make PHP run on .js pages? -


I'm curious about passing PHP output to JavaScript Especially two things:

  • I assume that the script tag on this .php page can be safely used. Is there no reason?

  • Can you run PHP on .js pages? What configuration changes would be required? And then, is there any reason?

    I agree that this is a .php page The script tag can be used safely on the screen. Is there no such reason?

    Yes no reason

    Can you run PHP on .js pages? What configuration changes would be required? And then, is there any reason?

    Yes, you have to use the PHP module for your webserver for a .js suffix. On Nginx, you can add a space row for files ending in .js: -

      location ~ \ .js $ {}   

    Apache But you want to do something like this: -

      AddType application / x-httpd-php .php .js   

    One reason may be that you Do not do this, any static JS files will have to go through the PHP module and this will cause additional overhead. Another option is HTML script tags like: -

      & lt; Script src = "myfile.php" & gt; & Lt; / Script & gt; Will reference the PHP file in   

    And then make sure that your PHP returns the right output with the right content type like: -

      header ('Content-Type: App / Javascript ');    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -