2021 Cloudflare: Basic Pages Rules and Cache Levels, Standard and "Cache Everything"
Summary
TLDR这个视频讲解了如何在Cloudflare设置页面规则来优化网站缓存和性能。首先,设置一个通配符规则,将缓存级别设置为"缓存全部",这将缓存所有页面,包括动态生成的PHP页面。然后启用自动压缩CSS和JavaScript文件的功能,以减小文件大小。接着,设置一个月的缓存有效期。为了避免缓存某些动态页面,可以为特定页面设置"绕过缓存"规则,如联系表单页面等。通过设置页面规则,网站所有者可以优化缓存策略,提高网站性能和用户体验。
Takeaways
- 👉 主要解释了Cloudflare的页面规则功能。
- 🔑 页面规则可以应用于特定页面或整个网站。
- 🌐 使用通配符(*)可以将规则应用于所有页面。
- 💾 缓存等级可以设置为"标准"或"全部缓存"。
- 💻 "全部缓存"会缓存动态页面(如PHP页面)的内容,导致内容不再随机生成。
- 🛠 可以为特定页面设置"绕过缓存"的规则,以防止缓存动态内容。
- 🔄 自动缩小CSS和JavaScript文件可以减小文件大小。
- 🕰 可以设置文件的缓存时间,例如1个月。
- 🔑 针对不同页面应用不同的缓存规则很重要,避免缓存不应该缓存的内容。
- 💻 要根据网站的实际情况和需求,合理设置页面规则。
Q & A
Cloudflare为域名提供了多少免费的页面规则?
-Cloudflare为每个域名提供了三个免费的页面规则。
在Cloudflare中设置页面规则时,星号(*)的作用是什么?
-在Cloudflare页面规则中,星号(*)作为通配符,可以匹配任何内容。比如,如果规则应用于'index*',它可以匹配'index.php'、'index.html'等任何以'index'开头的页面。
页面规则中的'缓存级别'设置默认值是什么?
-页面规则中的'缓存级别'设置的默认值是'标准',这会缓存如图片、JavaScript和CSS等常规内容。
选择'缓存所有内容'对动态页面有什么影响?
-选择'缓存所有内容'会缓存动态页面,如PHP页面,这意味着这些页面会被保存在Cloudflare的边缘服务器上,对所有用户显示相同的内容,不再动态生成。
为什么要小心使用'缓存所有内容'设置?
-使用'缓存所有内容'设置时要小心,因为它会缓存动态生成的内容,如随机生成的图片列表,这可能不适合所有网站,尤其是内容经常变化的网站。
在设置页面规则时,如何排除某些页面不被缓存?
-可以通过为特定页面设置不同的页面规则来排除它们不被缓存,比如将缓存级别设置为'绕过',以确保动态内容,如含有联系表单的页面,不被缓存。
页面规则中的'自动压缩'有什么用途?
-'自动压缩'功能可以压缩CSS、JS文件,减少文件大小,提高网页加载速度。
如何设置Cloudflare页面规则以优化静态网站的性能?
-对于静态网站,可以通过设置'缓存所有内容'和'自动压缩'等页面规则来优化性能,这样可以缓存网站的所有内容,并压缩代码来加快加载速度。
在Cloudflare页面规则中,如果不希望缓存某个特定页面,应如何操作?
-如果不希望缓存某个页面,可以为该页面创建一个页面规则,并将缓存级别设置为'绕过',这样可以确保页面内容动态生成,不被缓存。
Cloudflare页面规则的设置对网站性能和用户体验有什么影响?
-正确设置Cloudflare页面规则可以显著提高网站性能和用户体验,通过缓存内容和压缩文件减少加载时间,同时允许动态内容保持更新,平衡速度与实时性。
Outlines
🌐 设置Cloudflare页面规则
本段落详细介绍了如何在Cloudflare上设置页面规则以优化网站性能。首先,指出大部分DNS指向Cloudflare时,可能需要设置页面规则。通过点击域名下的页面规则选项,用户可以免费获取三个页面规则。页面规则的设置包括使用通配符(*)来应用规则于网站的所有页面,例如index.php或admin/users.php等。主要讨论了缓存级别设置,包括标准缓存和缓存所有内容的差异,以及如何谨慎使用缓存以避免动态内容被错误缓存。通过例子说明了缓存设置的影响,包括如何使动态生成的内容(如随机显示的公寓照片)被全球的Cloudflare服务器缓存。最后,提到了针对几乎静态的网站如何设置缓存规则,并简要介绍了自动压缩CSS和JS的选项。
📤 特定页面缓存策略
第二段落解释了如何为特定页面设置不同的缓存策略,以处理可能需要动态内容更新的页面。使用了一个例子来说明,即使网站没有联系页面,但有关于页面(about.php)可能包含联系表单等动态内容,因此选择为该页面设置“绕过缓存”规则,确保该页面不被缓存。这样做可以保持页面内容的实时更新,避免因缓存导致的信息滞后或错误显示。简单地总结了基本页面规则的设置方法和考虑因素。
Mindmap
Keywords
💡DNS
💡Cloudflare
💡页面规则
💡缓存级别
💡自动压缩
💡边缘服务器
💡静态网页
💡动态网页
💡通配符
💡联系表单
Highlights
我们大部分的域名都指向 Cloudflare,你可能需要设置页面规则。
页面规则做了什么?首先,我刚才所做的将应用于我网站上的所有页面。
星号(*) 表示通配符,会匹配任何后续内容。
首先你会希望处理缓存级别的设置。默认情况下它设置为标准,这会缓存你的图像、JavaScript 和 CSS 等常规内容。
如果你点击"缓存全部",它将缓存你的动态页面,例如 PHP 页面,而不是 HTML 页面。
你必须对此非常小心,因为在此网站上,这些公寓的照片是随机生成的,每次有人请求页面时,你都会看到不同的公寓。
在设置页面规则为缓存全部后,Cloudflare 在全球数百个不同的边缘服务器上会缓存这个页面。
因此,特定公寓 ID,如 1742 和 1402,会开始对每个人显示相同的页面,不再随机动态生成内容。
有时这正是你想要的,有时则不是,你可以使用页面规则指定该设置应用于哪个特定页面或页面组。
对于这个西班牙词频词典网站,它基本上是一个静态网站,我想缓存全部内容。
我们还可以自动压缩 CSS、JS 等以减小代码体积。
让我们为这条缓存规则设置一个月的缓存过期时间。
现在让我们创建另一条页面规则,因为我可能想要对某些页面有更多控制。
对于联系人页面 contact.php(实际上没找到),让我们将缓存级别设置为绕过全部,这样我们就不会缓存这个可能包含动态联系表单的页面。
这些是一些基本的页面规则。
Transcripts
okay
now
all of our dns or not all of it most of
it is pointing to cloudflare
and you're probably going to want to set
up a page rule or two
okay so here's our domain and you want
to click here on page rules
you get three of them for free
all right
so let's do that
now what do these page rules do
all right so first of all
what i just did
will
apply to all the pages on my website
okay this asterisk will anything that
were to come after it
if i said uh
index
then that would apply to
index.php or index.html
or
anything if i put in let's say
admin
right then that would apply to
admin
uh
users.php it would apply to admin
uh
it would apply to anything that came
after it it would apply to admin
uh
panel.php any right you get it so it's a
wild card
so this page rule will apply to
all the pages
and the first setting you surely will
want to deal with is the cache level
okay by default it is set to standard
and standard will do things like it will
cache your images javascript css the
normal stuff
but then
if you click cache everything
that will cache your dynamic pages for
example your php pages
not your html pages and your php pages
so you have to be very careful with this
on this website here you can see
index.php
uh i tested it it does it does exactly
what it says it will do
all of these uh photos here these
apartments they're generated randomly
every time someone requests the page you
have a different set of apartments that
pop up
right so after you set
uh your rule to cache everything
on your edge points right your cloud
players
hundreds of different servers spread out
across the globe
it will cache
all of this
such that
apartment
id
1742
1402
this exact page will start appearing to
everybody
the same no matter what no matter how
many times they request the page you
will no longer see it it they won't
randomly
uh dynamically generate that content for
the people that request your page now
sometimes that's what you want but not
always and you can use your page rules
to specify
when this setting will apply to a
particular page or hear a group of pages
now in the case of this spanish
frequencydictionary.com
it's basically a static site i want to
cache everything okay
i'm going to make one exception in a
minute but
for now we're just going to
stay with this okay
so we've got cache everything it's going
to do that let's add another one
auto minify
i want to auto minify my css jss
js
if essentially if you don't know what
that means you can look it up but it
will compress your code
alright
um
now let's do another one
where is it
no i don't want that
oh yeah okay
let's set this out to a month
okay so we've got all these
um
and
let's save that
all right so we've got there's our one
page rule now let's create another one
because
i may
want to
uh
i may want to have
a little more
and let's just do
contact.php
what do we have here on this
oh wait a minute
do i have a contact no i don't have a
contact page
i've got this so what do i have oh i
have it on my about page
um
okay
well i guess we'll just do
about php
so
we'll put our cash level to bypass all
right so now uh we're not going to cache
this page
because i might
have that page be dynamic with a contact
form that that sort of thing and so i
don't want to cache that page
okay so
those are some basic page rules
5.0 / 5 (0 votes)