Skip to content

Commit 4d9ab95

Browse files
jonsgreencodyjamesbrooks
authored andcommitted
Configure Fast.ly
- adds documentation for caching [Configure Fast.ly](https://miro.com/app/board/uXjVO6C1LxA=/?moveToWidget=3458764524414700733&cot=14)
1 parent cf61bf4 commit 4d9ab95

File tree

2 files changed

+89
-34
lines changed

2 files changed

+89
-34
lines changed

app/views/staff/websites/_form.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
= f.input :twitter_handle
2828
= f.input :facebook_url
2929
= f.input :instagram_url
30-
= f.input :domains
3130
.col-md-6
3231
%fieldset
3332
%legend.fieldset-legend Configure Website Session Formats
@@ -73,7 +72,8 @@
7372
= ff.input :description
7473
= image_input(ff, :image)
7574

76-
%legend.fieldset-legent Caching
75+
%legend.fieldset-legend Domains/Caching
76+
= f.input :domains
7777
= f.input :caching, collection: Website.cachings, include_blank: false
7878
.row
7979
.col-sm-12

docs/website_documentation.md

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,6 @@ for the content.
6969
this will also populate the `tiwtter:site` meta tag in the head.
7070
- Facebook url: full url to the facebook page for the event.
7171
- Instagram url: full url to the instagram page for the event.
72-
- Domains: a special field that deserves its own treatment [as follows](#domain-configuration).
73-
74-
### Domain Configuration
75-
76-
Once created, an event website can always be accessed from your cfp-app domain with
77-
the event slug in the path. For example, rubyconf 2022 hosted by Ruby Central
78-
could be accessed at `https://cfp.rubycentral.org/rubyconf-2022`.
79-
80-
However, most conferences will prefer to have a custom domain which can be
81-
achieved by following the steps below. Note that these instructions are for websites
82-
hosted on Heroku but something similar can likely be achieved with whatever
83-
hosted solution being used.
84-
85-
1) Add your custom domain to the Website on the configuration page. Note that
86-
multiple domains can be added by separating them with commas in the input.
87-
Currently only domain matching is supported so do not include any subdomain like
88-
'www' (i.e. just `rubyconf.org`).
89-
2) Add your domain to your heroku hosted cfp-app. This can be done using the
90-
heroku-cli following [these
91-
instructions](https://devcenter.heroku.com/articles/custom-domains) or from the
92-
`Settings` section in the dashboard. Note that you will likely need to configure
93-
SSL certificates as well.
94-
3) You will also need to [Configure your
95-
DNS](https://devcenter.heroku.com/articles/custom-domains#configuring-dns-for-root-domains)
96-
to point to the heroku DNS target for your app.
97-
98-
There is a section in the [routes file](/config/routes.rb/) wrapped with a
99-
`DomainConstraint` that allows the most recent active website to be accessed at
100-
the root of your domain. So, with the example from above, Rubconf 2022 can be
101-
found at `https://rubyconf.org`. Older conferences that share the same domain
102-
can also still be accessed by simply appending the event slug. Hence, Rubyconf
103-
2021 could be reached at `https://rubyconf.org/rubyconf-2021`.
10472

10573
### Configure Website Session Formats
10674

@@ -214,6 +182,93 @@ website including title, description, open graph and twitter tags. Fields includ
214182
- image: a file field for uploading an image that will populate the url for
215183
`og:image` and `twitter:image`
216184

185+
### Domains/Caching
186+
187+
#### Domain Configuration
188+
189+
Once created, an event website can always be accessed from your cfp-app domain with
190+
the event slug in the path. For example, rubyconf 2022 hosted by Ruby Central
191+
could be accessed at `https://cfp.rubycentral.org/rubyconf-2022`.
192+
193+
However, most conferences will prefer to have a custom domain which can be
194+
achieved by following the steps below. Note that these instructions are for websites
195+
hosted on Heroku but something similar can likely be achieved with whatever
196+
hosted solution being used.
197+
198+
1) Add your custom domain to the Website on the configuration page. Note that
199+
multiple domains can be added by separating them with commas in the input.
200+
Currently only domain matching is supported so do not include any subdomain like
201+
'www' (i.e. just `rubyconf.org`).
202+
2) Add your domain to your heroku hosted cfp-app. This can be done using the
203+
heroku-cli following [these
204+
instructions](https://devcenter.heroku.com/articles/custom-domains) or from the
205+
`Settings` section in the dashboard. Note that you will likely need to configure
206+
SSL certificates as well.
207+
3) You will also need to [Configure your
208+
DNS](https://devcenter.heroku.com/articles/custom-domains#configuring-dns-for-root-domains)
209+
to point to the heroku DNS target for your app.
210+
211+
There is a section in the [routes file](/config/routes.rb/) wrapped with a
212+
`DomainConstraint` that allows the most recent active website to be accessed at
213+
the root of your domain. So, with the example from above, Rubconf 2022 can be
214+
found at `https://rubyconf.org`. Older conferences that share the same domain
215+
can also still be accessed by simply appending the event slug. Hence, Rubyconf
216+
2021 could be reached at `https://rubyconf.org/rubyconf-2021`.
217+
218+
#### Caching
219+
220+
At a certain point in the lifecycle of your website it may be desirable to add
221+
some caching for the static and dynamic pages for your conference especially
222+
right before and during your event.
223+
224+
Currently caching is somewhat hardcoded to only support
225+
[Fastly](https://www.fastly.com/) as a caching CDN proxy. If you would like to
226+
use a different service please contact the CFP app team and we will help you
227+
develop an adapter for a different provider.
228+
229+
To use Fastly you will need to add ENV variables for `FASTLY_API_KEY` and
230+
`FASTLY_SERVICE_ID`. This will enable the FastlyService to be instantiated on
231+
server boot.
232+
233+
By default the caching setting is set to `off`. When you are ready to enable
234+
caching you can change the setting to `automatic` or `manual`. `automatic`
235+
caching will automatically purge all of your website content anytime you save
236+
the website configuration or a page or sponsor. However, it will not purge when
237+
program sessions or time slots change. In that case you will need to resort to
238+
using the `Purge` button at the top of the Website configuration page. With the
239+
setting set to `manual` you will always need to use the `Purge` button to clear
240+
the public Fastly cached content for your website. This setting can therefore be
241+
used to somewhat set the page and program content for your website and only
242+
update when you ready for a set of changes to become visible. If you ever want
243+
to turn caching back to `off` be sure to also `Purge` your cache so that new
244+
requests will miss the Fastly cache and hit the server instead.
245+
246+
Caching is controlled with various response headers that browsers and especially
247+
Fastly recognize. We recommend keeping browser caching turned off or very low.
248+
You are able to influence this with the `CACHE_CONTROL_MAX_AGE` ENV variable which
249+
populates the max-age setting in the `Cache-Control` response header and
250+
defaults to 0 but can be set to however many seconds you wish the browser to
251+
cache the page.
252+
253+
Fastly will instead read from the `CACHE_CONTROL_S_MAXAGE` ENV variable which
254+
defaults to 604800 (1 week) and populates the s-maxage setting in the
255+
`Cache-Control` response header. Note that when caching is turned off the
256+
`Cache-Control` is set to private and otherwise is set to public.
257+
258+
It is also worth noting that a custom Fastly
259+
[`Surrogate-Key`](https://developer.fastly.com/reference/http/http-headers/Surrogate-Key/)
260+
response header is added using the event slug as its value. The app will
261+
[`purge_by_key`](https://github.com/fastly/fastly-ruby#efficient-purging) using
262+
the event slug so that purging will be scoped to the current website in case you
263+
are using the same fastly service for multiple websites/events.
264+
265+
Finally, `Etag` and `Last-Modified` response headers are added when caching is
266+
turned on based on the `website#purged_at` timestamp using the convenient Rails
267+
[`fresh_when`](https://api.rubyonrails.org/classes/ActionController/ConditionalGet.html#method-i-fresh_when)
268+
helper. This adds another level of cache validation for Fastly and/or browser
269+
by returning a 304 Not Modified response if an If-Modified-Since
270+
header comes through a request and is greater than the purged_at datetime.
271+
217272
## Page Content Management
218273

219274
You can add static pages to your website by navigating to the `Pages` section in

0 commit comments

Comments
 (0)