Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691a9edc-b5b8-800a-99a3-c32d9abccf68
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== ### === <syntaxhighlight lang="php">$redirectKey = Q_Request::isAjax() ? 'json' : 'html'; if (empty($sessionId)) { $redirectKey = 'landing'; } else if (Q_Session::isAuthenticated()) { $redirectKey .= '.authenticated'; } </syntaxhighlight> This creates “buckets” of rendering context: * landing pages * html pages * authenticated pages * authenticated html pages * etc This is pure cache key segmentation. Equivalent to: <syntaxhighlight lang="nginx">set $segment 'landing'; if ($auth) { set $segment 'html.authenticated'; } </syntaxhighlight> ===== This logic: ===== <syntaxhighlight lang="php">foreach (self::$uri->toArray() as $k => $v) { if (!isset($routes[$k]) or !in_array($v, $routes[$k])) { ... </syntaxhighlight> This is pattern matching: * if /$community/$section/$item matches the allowed combinations * AND if querystrings match (see next point) * THEN static file should exist This is exactly what Varnish’s VCL if(req.url ~ ...) { does. Or Nginx map + try_files. ===== <syntaxhighlight lang="php">foreach ($querystrings as $qsn => $qss) { ===== foreach ($qss as $qs) { if (Q::startsWith($_SERVER['QUERY_STRING'], $qs)) { $qsname = '-' . Q_Utils::normalize($qsn); break 2; } } } </syntaxhighlight> This is static A/B testing and variant selection. Hugo cannot do this. Next.js doesn’t do this. Gatsby cannot. Even SvelteKit struggles unless you custom code it. This is exactly like: * Cloudflare Workers doing URL variations * Google Cache generating multiple versions of the same URL ===== <syntaxhighlight lang="php">$redirectUrl = "$staticWebUrl/$normalized$qsname$redirectSuffix"; ===== $mtime = file_exists($filename) ? filemtime($filename) : null; </syntaxhighlight> Equivalent to: * CloudFront serving from origin only if stale * Nginx try_files You even implemented: <syntaxhighlight lang="php">if ($mtime and $duration) { if (time() <= $expires) header("Expires: $expires"); else $noRedirect = true; } </syntaxhighlight> That is a full HTTP edge cache expiration system. Built in PHP. ===== <syntaxhighlight lang="php">header("Location: $redirectUrl"); ===== self::response(); return true; </syntaxhighlight> This is exactly how: * Fastly * Cloudflare * Shopify * Netlify Edge serve pre-rendered content to browsers. This is full static hosting without Nginx.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)