1

This particular project is huge, both in data and in user access (personaly I wouldn't use WP but the client wants to).

The problem is, I don't want the front-end to constantly access the database, so is there a way to make WordPress generate a JSON that I can use in the front-end?

I found one called WORDPRESS JSON API, but it doesn't seems to do this, it still access the DB on each request.

  • Build an associative array of the data you want on the server, json_encode() it, deliver it to the browser. I really don't see the "problem" you describe though - this is what a database is meant to do. Sticking what could amount to tens to hundreds of megabytes of data into a massive JSON structure in browser memory seems like a bizarre premature "optimization". – bosco Jul 19 '16 at 18:26
  • I don't think you got the way I want these JSONs structured. They wouldn't be a copy of the DB. The result would be hundreds of megabytes in memory. That's absolutely NOT the case. What I need is something like a cache. But I imagined there wouldn't be anything like this in WP. The current website of this client I developed with JSONs like I described. They were a target of several DDoS attacks and never went down. That's why I can't use DB in the front-end. For the new one i think I'll need to create an intermediate tool to treat the DB and create these JSONs. – N. Reek. Jul 19 '16 at 19:12
  • 1
    yes bias against wordpress is the "thing" in technical circle, if only the people that spread the bias have spent the same amount of time learning it, they might have stopped. Your concerens are a solved thing in the community for years (8 years? more?) now.. Actually the solution is so good (enough) that now when the time is to move on into dedicate caching software the community is stuck with the plugin. But if you are starting from scratch, solving caching in app layer is just wrong, use varnish or webserver caching for that. – Mark Kaplun Jul 20 '16 at 4:27
2

After pondering your question some I am guessing you mean to generate actual physical JSON file in filesystem to use as data source? That would certainly be unorthodox in WP development.

Typically in WP you try to minimize disk access, since it is more likely to be a bottleneck in general. Doing file writes is quite inconvenient in WP extension meant for public distribution, but in private of specific server you could generate and dump JSON into a file rather trivially.

For a more "WordPress way" of doing things you might want to look into persistent Object Cache. WP can be made to use persistent memory cache (such as APC, Memcache, Redis, etc), which both greatly increases its general performance and makes it possible to cache data there via WP APIs.

  • Thank you, I'll take a look on those. If none of them fit I plan to create an intermediate tool to generate these JSONs. I just need the Wordpress for the admin, I prefer not to develop "themes". – N. Reek. Jul 19 '16 at 19:15
2

If you're looking to create a JSON feed from your WordPress site, you should almost certainly be using the REST-API plugin. It's robust, well-documented, and slated for inclusion in WordPress core at some point in the future.

There is a caching plugin available for the REST-API that will cache any JSON output to disk for future requests. Disk caching in WordPress decreases access times by a factor of 10x in my experience, and is worth looking into.

1

Wordpress REST API is in-built and working already in newer versions of Wordpress.

https://www.codeinwp.com/blog/wordpress-rest-api/

To access the WordPress REST API, you’ll need to start with the following route:

yoursite.com/wp-json/wp/v2

or

yoursite.com/?rest_route=/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.