Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Warm paginated pages with static:warm command #9493

Open
wants to merge 13 commits into
base: 4.x
Choose a base branch
from

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Feb 8, 2024

This pull request implements warming of paginated pages into the static:warm command. This will be especially useful for larger sites which have lots of pagination pages since right now, only the first page is warmed.

Under the hood, Statamic's Cache middleware checks if there's a paginator instance being "blinked". If there is, a header is added to the response containing the URL of the next paginated page.

This header then gets picked up by the static:warm command and triggers the paginated page to be warmed, which happens in a loop until there's no more paginated pages to warm.

The implementation is inspired by statamic/ssg#140.

Working around the ignore_query_strings config option

Right now, you can't use pagination at all with the ignore_query_strings config option enabled. This PR adds the ability to whitelist certain query parameters, like the page query param used for pagination.

// config/statamic/static_caching.php

'ignore_query_strings' => true,

'allowed_query_parameters' => [
    'page',
],

I've made this a config option rather than hard-coding page so it's flexible in case you have a reason for a query parameter changing the outputted HTML.

One downside to this approach (which is potentially a non-issue, depending on your reason for using the ignore setting in the first place) is that the allowed query parameters can be used on any page, even where it's not used, and it would result in a separate page in the cache.

For example: If you have page on the allow list and only have a "News" page with pagination on it, users could append ?page=whatever to any page and a separate page would be created in the cache.

To Do

  • Figure out how it works alongside the ignore_query_strings setting
    • We could potentially make it work so it ignores query strings apart from page (or whatever the page name you've defined)
  • Fix paginated pages being output as / in the list of warmed URIs
  • Make it work with queued warming

@duncanmcclean duncanmcclean changed the title [4.x] Warm paginated pages [4.x] Warm paginated pages with static:warm command Feb 8, 2024
duncanmcclean and others added 7 commits February 9, 2024 16:35
By default, we'll have the `page` query parameter in here so pagination works.

However, if you change the pagination param name or have some other query parameter you want to whitelist, then that setting lets you do that.
@duncanmcclean duncanmcclean marked this pull request as ready for review February 12, 2024 15:19
jasonvarga

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants