Search code examples
phpcachingbrowser-cacheurlvariables

URL variables and PHP redirects, can they be cached?


Two questions rolled into one.

Can browsers in general cache a URL (js script) if it's requested with URL variables? E.g. www.thing.com/?l=lib&s=thing.js

Can browsers cache a file if it is a php redirect? E.g. www.thing.com/script.js (called, is a php file with a redirect to www.thing2.com/actual.js)

Thanks.


Solution

  • Since you have two questions

    1. Can browsers in general cache a URL (js script) if it's requested with URL variables? E.g. www.thing.com/?l=lib&s=thing.js

      Yes.

    2. Can browsers cache a file if it is a php redirect? E.g. www.thing.com/script.js (called, is a php file with a redirect to www.thing2.com/actual.js)

      Depends. If the redirect is a 301, then yes per the spec

      The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.

      If the redirect is a 302, then maybe

      The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.