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?

Drop us a note.

No matter where you are in the planning process, we’re happy to help, and we’re actual humans here on the other side of the form. 👋 We’re here to discuss your challenges and plans, evaluate your existing resources or a potential partner, or even make some initial recommendations. And, of course, we’re here to help any time you’re in the market for some robust WordPress awesomeness.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.