Posted By

catswhocode on 08/21/17


Tagged


Versions (?)

How to add expire headers for external scripts


 / Published in: PHP
 

URL: https://www.catswhocode.com/blog/php-how-to-add-expire-headers-for-external-scripts

Create a file named externaljs.php. Then link to it:

  1. <?php
  2.  
  3. $files = array(
  4. 'ga.js' => 'https://ssl.google-analytics.com/ga.js',
  5. 'bsa.js' => 'https://s3.buysellads.com/ac/bsa.js',
  6. 'pro.js' => 'https://s3.buysellads.com/ac/pro.js'
  7. );
  8.  
  9. if(isset($files[$_GET['file']])) {
  10. if ($files[$_GET['file']] == 'ga.js'){
  11. header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + ((60 * 60) * 48))); // 2 days for GA
  12. } else {
  13. header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60))); // Default set to 1 hour
  14. }
  15.  
  16. echo file_get_contents($files[$_GET['file']]);
  17. }
  18.  
  19. ?>

Report this snippet  

You need to login to post a comment.