Most of WordPress users are aware of performance being important for their SEO, and more importantly for their visitors. The most common practice is to use a cache plugin to ensure their website is as fast as possible. But you might encounter some side effects, especially with WP-AppKit.
WP-AppKit Web Services
One important thing is to first understand how WP-AppKit plugin works to send data to mobile apps.
A WP-AppKit app is interacting with your WordPress website thanks to Web Services. Here is how it’s done:
- the app calls an URL from WP-AppKit API, for example to initialize app content: http://www.example.com/wp-appkit-api/[app-slug]/[security-token]/synchronization/
- WordPress answers (if WP-AppKit is installed and activated) with a JSON file containing app data
- WP-AppKit inserts into this answer specific HTTP headers allowing the interaction between website and app
Now that you understand that, you’ll surely understand the next step: cache plugins side effects.
Cache Plugins Working Principle
When someone (or something) calls an URL on the website, cache plugins intercept this call, let the web server build the corresponding page, and then memorize the result.
As soon as this exact same URL is called again, cache plugins don’t let the web server build the page one more time and directly return the memorized result.
Problems this may cause with WP-AppKit are the following:
- cache plugins usually add HTML comments at the end of each page, like <!– This page has been optimized by my-cache-plugin –>. When such a plugin adds it at the end of JSON return from WP-AppKit Web Services, this response becomes invalid and the app cannot interpret it anymore.
- HTTP headers sent when cache plugins return their stored pages don’t contain the ones allowing the app to interact with the website
In order to avoid these issues, you should always add WP-AppKit Web Services URLs to your cache plugin exceptions. You will find it in a setting like “Don’t cache the following pages“.
WP-AppKit Web Services URLs all begin with /wp-appkit-api/ so this is the only thing you’ll have to add into this setting.
An Example Through WP-Rocket
[UPDATE] As of WP-Rocket version 2.9, you don’t need to do this anymore, since the plugin is compatible with WP-AppKit by default now. This chapter remains as it still can be useful to understand what’s needed for other plugins.
In this section, we show you the way to configure one of current major cache plugins: WP-Rocket. This is relatively simple, since the option we need to update is available via an admin screen.
Here is what you need to accomplish:
- Go to your admin panel
- Click “Settings > WP Rocket”
- Go to “Advanced options” tab
- Enter the following value into “Never cache the following pages:” field: /wp-appkit-api/.*
This will result in excluding all URLs beginning with /wp-appkit-api/ from the caching system, and allowing your mobile apps to get your content as expected.
On some cache plugins you must also add /wp-content/plugins/wp-appkit/app/.* to the excluded urls for the preview to work.
Please note that depending on the cache plugin you may use, the way of avoiding these issues could vary, so please feel free to comment on this post and give us your feedback and/or specific cases you may have encountered with some plugins!
Happy app coding 🙂