Search code examples
cachingcache-control

how to check if a site has enabled Cache-Control for a file type


I was wondering if there is any way to check if a website has enabled Cache-Control for a file type and its expiry time example for http://foo.com/foo.css how can i know if Cache-Control is enabled for it and whats is the expiry time set for it


Solution

  • You can try this:

    <?php
    $temp = curl_init();
    curl_setopt( $temp, CURLOPT_URL, 'http://foo.com/foo.css' );
    curl_setopt( $temp, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $temp, CURLOPT_CONNECTTIMEOUT, 20 );
    curl_setopt( $temp, CURLOPT_HEADER, true );
    curl_setopt( $temp, CURLOPT_NOBODY, true );
    echo curl_exec( $temp );
    curl_close( $temp );
    ?>
    

    This will return an output like This:

    HTTP/1.1 200 OK Server: Date: Current Date GMT Content-Type: text/css Content-Length: 2713 Connection: keep-alive Vary: Accept-Encoding Last-Modified: Date of file creation Accept-Ranges: bytes Cache-Control: max-age=expiry time in sec set for it Expires: Expiry Date GMT