Serve PHP files as JavaScript output

It would be often good to embed .js file output with dynamic content.

The trick is very simple:

  1. We will request Apache search for .php files if we request their .js file. For example, variables.php file will exist physically and contain the PHP scripts inside it. But it will be accessed as variables.js.
  2. We will inject the correct header: header(‘Content-Type: text/javascript’);
  3. The PHP Script will output valid JavaScript.

Examples:

There may be some questions that may strike your brain could be the reason of moderate condition belongs to long-phase of chronic health problem like heart diseases, high blood pressure, blood sugar level, vascular problem, multiple sclerosis etc. viagra tablet price Childhood experiences of abuse or trauma are risk factors viagra free order for a condition like heart attacks and strokes. Erection-helping medicine is one among all available treating cheap levitra appalachianmagazine.com methods. The best Osteopaths are skilled rehabilitation spe cialis pills onlinets who can help patients recover from any type of pain that one experiences once they have misaligned Spine, back and as well as neck. js/.htaccess

RewriteEngine On
RewriteRule (.*?)\.js $1.php [QSA]

js/variables.php

<?php
header(‘Content-Type: text/javascript‘);
?>
var today = ‘<?php echo date(‘Y-m-d’); ?>’;

You can now call <script src=”js/variables.js”></script>, which will always contain today’s date (dynamic).