Search code examples
phpurlcachingbrowser-cache

(with )Wrapped css,js cache is not working with even same url


How Wrapper class works

I created php class and now I am able to do this to put together all my css,js .It works like this Wrap::set(array(file.css,file2.css,file3.css)) then I wrote wrap::call_path and it begin to generate url like this www.example.com/wrap_contects?path[]=file.css&path[]=file2.css&path[]=file3.css then in the server side I get all paths with in the array then I tried file_get_content for each of them,after that I wrote echo all results.It put together all CSS,if I wrote JS it will be JS.

Problem

Problem is browser is not cache this url.

Note

I consider all security issues,I created token to send wrap_content.php to prevent file get content to work for any file that user request


Solution

  • I solved this problem,hope it will help someone who has same problem to solve this problem in the future I added these ones to wrap_contents.php:

    $cache_length=60*24*30;
    $cache_expire_date = gmdate("D, d M Y H:i:s", time() + $cache_length);
        header("Expires: $cache_expire_date");
     header("Pragma: cache");
    header("Cache-Control: max-age=2592000");
    
    (if css) header("Content-type: text/css");
    
    (if js) header('Content-Type: application/javascript');
    

    This created css,js simulator on the response with php file.