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:

  1. Go to your admin panel
  2. Click “Settings > WP Rocket”
  3. Go to “Advanced options” tab
  4. Enter the following value into “Never cache the following pages:” field: /wp-appkit-api/.*
WP Rocket options to make WP-AppKit compatible

WP Rocket options to make WP-AppKit compatible

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 🙂

Published by Lionel on October 9, 2016

Web Developer for an insurance company, WordPress since 2009, aware about front-end performance and curious about (almost) anything

3 Comments

  1. Very nice article. Very easy to understand. Thanks a bunch from Indonesia <3 😀

    Reply
  2. Please Lionel, Ben and Co. you guys should step up your game. To me the last two post posted here in the blog section is not much needed, Should you add polls here and list the features which we your users want a tutorial on or implemented, I can bet my last penny that its not caching and photoswip, Every app nowadays support or uses the listed below features…..

    — Swipe for menu

    — Slider

    — Social sharing and others

    I know most of your users will be happy if you do this.

    Reply
    • Hi, thank you for your feedback. First let me explain how the tutorial subjects are chosen: they’re the most common issues we have in support tickets that can be answered with a tutorial. So, for that part, I can assure you that touch enabled swipe galleries and caching were very much asked and needed. We also store any suggestion that comes through Facebook, GitHub, mail… You can see that as a permanent poll over the last 3 years 🙂 Regarding touch gestures, it is certainly something we’ll implement in the future using HammerJS as most of our users do currently. You have to understand that we build and support WP-AppKit on our free time and so we have to choose carefully how we use it. It means that we can’t answer to all questions and requests. The features you list are on our list except for sliders (which can be achieved with Photoswipe BTW). As for any open source project, we also welcome contributions (we already had several and we deeply thank the contributors). Themes are probably the best way to begin contributing. Q themes are available on Github and open to pull requests. Anyway, I keep the poll idea if we ever fell short of ideas or to get most wanted features for the next release. Again thank you.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Having questions?

FAQ | Tutorials | Documentation

Or

Contact Us