JosephSilber / page-cache

Caches responses as static files on disk for lightning fast page loads.
MIT License
1.21k stars 118 forks source link

How to cache paginated urls? #97

Open hmzisb opened 2 years ago

hmzisb commented 2 years ago

Paginated pages return the same content as first page. As there any way around it?

1stwebdesigns commented 2 years ago

@hmzisb the issue is that Laravel uses a query string for pagination. I did see a solution for caching views that have query string parameters, but I don't particularly like this because a bot could generate a huge number of cached files by just changing the query string slightly each time.

The solution I used was to implement pretty pagination - that is where the page number forms part of the route, rather than using a query string. I used this package: https://github.com/michaloravec/laravel-paginateroute

So your URLs become /products/widgets/2 rather than /products/widgets?page=2

hmzisb commented 2 years ago

@1stwebdesigns Thanks for the help. I saw this package but it seems like it hasn't been maintained in the last three years. Does it still work with the latest version of laravel?

1stwebdesigns commented 2 years ago

@hmzisb Yes it works fine - although it was created 3 years ago I have seen the author reference it on the Laravel forum more recently. In my case it was a choice between disabling the caching of paginated pages, implementing a work-around to cache pages with query strings, or implement pretty pagination. The latter seemed the lesser of 3 evils. Not to mention I think pretty pagination looks nicer, so there is a benefit there.