Using WP_Rewrite instead of _GET parameters to leverage full page caching

Often in code we’re used to doing something like this http://example.com/my-great-article/?all_pages=1 But this doesn’t play nice with full page caching provided by batcache. To leverage full page cache we need to use the WP_Rewrite API, you can use rewrite endpoints Or use the add_rewrite_rule() and add_rewrite_tag() functions (guide here)

With the help of these functions you can rewrite your url so that it will now be: http://example.com/my-great-article/all_pages/

But wait there’s more!

You can even speed up ajax requests with this technique.

You can create http://example.com/ajax/my_frontend_ajax_function/parameter_1/ to make ajax requests that are cached for 5 minutes for all users with batcache. This will make request time go down often 100 folds! Note that the ajax rewrites are to index.php and not to admin-ajax.php. You are creating a new endpoint that will call your PHP function, not rewriting the query to pass to admin-ajax.php

Ready to get started?

Tell us about your needs

Let us lead the way. We’ll help you select a top tier development partner. We’ll train your developers, operations, infrastructure, and editorial teams. We’ll coarchitect your deployment processes. We will provide live support for peak events. We’ll help your people avoid dark alleys and blind corners, and reduce wasted cycles.