Plack:...xpires(3pm)

πŸ“¦
version 0.06 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble

✨ NAME ✨

Plack::Middleware::Expires β€” literally mod_expires but for plack, bestie πŸ’…

It's the Perl module Plack::Middleware::Expires, and it's giving "Apache's mod_expires, but make it Plack." πŸ¦‹


🌸 SYNOPSIS 🌸

use Plack::Builder;

builder {
    enable 'Expires',
      content_type => qr!^image/!i,
      expires => 'access plus 3 months';
    $app;
}

πŸ’– DESCRIPTION πŸ’–

Plack::Middleware::Expires is Apache's mod_expires for Plack. No cap. 🫢

This middleware controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. It's the little glow-up your responses needed so browsers stop re-downloading everything like it's their first day on the internet. πŸ‘‘

Note, bestie, read this part: πŸ“Œ - Expires works only for successful response, πŸ’€ - If an Expires HTTP header exists already, it will not be overridden by this middleware. It knows better than to fight an existing header. πŸ™ˆ

πŸŽ€ CONFIGURATIONS πŸŽ€

content_type

content_type => qr!^image!,
content_type => 'text/css',
content_type => [ 'text/css', 'application/javascript', qr!^image/! ]

This is the Content-Type header to apply Expires to. Yes, it takes a regex, yes it takes a plain string, yes it takes an arrayref of both β€” she's flexible like that. ✨

also content_type accept CodeRef πŸ‘‡

content_type => sub { my $env = shift; return 1 if $env->{..} }

Expires

Same format as the Apache mod_expires, periodt. πŸ“

expires => 'M3600' # last_modified + 1 hour
expires => 'A86400' # access + 1 day
expires => 'modification plus 3 years 3 month 3 day'
expires => 'access plus 3 days'

Like... look at those options. M for last_modified, A for access, or spell the whole thing out like a main character. Either way, iconic. 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Masahiro Nagano <kazeburo {at} gmail.com>


πŸ¦‹ SEE ALSO πŸ¦‹

<http://httpd.apache.org/docs/2.2/en/mod/mod_expires.html>

(the og Apache mod_expires docs β€” go pay respects πŸ’œ)


⭐ LICENSE ⭐

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


perl v5.34.0 Β· 2022-06-16

k that's the whole page bestie, mwah πŸ’‹ β€” documented by the perl v5.34.0 girlies on 2022-06-16, slay πŸŽ€βœ¨

πŸ“¦ where this page comes from