How to add expire headers for external scripts


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.