How can I add expire headers for scripts that are not on my server?

后端 未结 9 837
我寻月下人不归
我寻月下人不归 2020-12-25 14:03

I have a website and I added the expire headers on all pages/images and scripts but I don’t know how I could add expire headers to external scripts.

For example Goo

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 14:15

    The only way is to create script which downloads contents from external site and then adds needed headers.

    
    

    To

    
    

    And external.php is something like

    Of course this has security hole so I'd recommend to use identifier strings like external.php?file=foo.js and then using

    $files = array('foo.js' => 'http://external/...');
    if(isset($files[$_GET['file']]))
    {
      echo file_get_contents($files[$_GET['file']]);
    }
    

    file_get_contents() of course will take some of your bandwith so it would be recommended to cache the result also.

提交回复
热议问题