bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

[Question] route url query cache #1189

Closed adeko closed 4 years ago

adeko commented 4 years ago

Could you please tell if there is a solution for caching route with random query string.

For example, I have URL: /assets.js?v=1585354010 And I use ROUTE: $f3->route('GET|HEAD /assets.js'

If works fine, but every time I change random number 1585354010, route creates new cache for this request.

I do not need that. I add random number for refreshing user browser cache.

But because of this, I have some problems with NNN of unused cached files, and also with some caching proxies.

[Question] Is it possible to ignore "?v=1585354010" part of url, and use for caching only main part of url "/assets.js", without rewriting this using nginx?

xfra35 commented 4 years ago

Just rewrite the URI variable (or $_SERVER['REQUEST_URI']) before calling f3->run().

adeko commented 4 years ago

Thank you. Looks like it worked.

I used in nginx: set $request_url $request_uri; if ($request_uri ~ ^(/assets.(js|css))\?(.*)$ ) { set $request_url $1; } fastcgi_param REQUEST_URI $request_url;

Now I use: $_SERVER['REQUEST_URI'] = preg_replace("!^(/assets.(js|css))\?(.*)$!i", "$1", $_SERVER['REQUEST_URI']); before calling f3->run().

Works the same.