retesere20

Untitled

Aug 22nd, 2016
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ==============USING PHP ================
  3. #using php header('Cache-control: max-age='.(60*60*24*365) .', public , must-revalidate');
  4. session_cache_limiter('none');
  5. // http://stackoverflow.com/a/1385982/2377343
  6. $year=60*60*24*365;//year
  7. //Caching with "CACHE CONTROL"
  8. header('Cache-control: max-age='.$year .', public');
  9. //Caching with "EXPIRES"
  10. //no need of EXPIRES when CACHE-CONTROL enabled
  11. //header('Expires: '.gmdate(DATE_RFC1123,time()+$year));
  12. //To get best cacheability, send Last-Modified header and ...
  13. header('Last-Modified: '.gmdate(DATE_RFC1123,filemtime(__file__))); //i.e. 1467220550 [it's 30 june,2016]
  14. //reply using: status 304 (with empty body) if browser sends If-Modified-Since header.... This is cheating a bit (doesn't verify the date), but remove if you dont want to be cached forever:
  15. // if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.1 304 Not Modified'); die(); }
  16.  
  17.  
  18.  
  19.  
  20. in Wordpress
  21. ==============================
  22. //Set or replace $regex_path_match accordingly
  23. if (preg_match($regex_path_match, $_SERVER['REQUEST_URI'])) {
  24. add_action( 'send_headers', 'add_header_nocache' );
  25. }
  26. function add_header_nocache() {
  27. header( 'Cache-Control: ............' );
  28. }
RAW Paste Data