In the latest release of Order Delivery Date v9.27.0 that is due to release by 2nd week of July, we have made a lot of performance changes.
- Removed the unnecessary ajax calls
- Used WC Ajax instead of admin-ajax
- Used REST API in place of some of the ajax calls.
Removed Unnecessary Ajax calls:
In the previous versions, we used the following ajax calls on the checkout page:
- Purpose : We used this ajax to fetch the first shipping method in a shipping zone. This would help in loading the custom settings for that shipping method when the page was loaded or when the shipping zone was changed after entering the address. This would also run when a shipping method was changed where it was not necessary.
- Triggered on actions: on page load, on change of shipping method
- Output: It returned the first shipping method of the shipping zone applied on checkout and the custom settings were applied based on that.
- Purpose : This ajax call checks for the common delivery days for custom settings of multiple categories. Although, this is only for the common settings, it was still called on various actions like on change of shipping method, or on selecting the date or even when checkout is updated.
- Triggered on actions: on page load, on change of shipping method, after every update_order_review ajax
- Output: It returned the common settings to be applied if more than one category product was added with different custom settings.
- Purpose: This ajax is used to check for the available time slots for a given date.This was called when a date was selected.
- Triggered on actions: This was called when a date was selected from the calendar.
- Output: The available time slots for the selected date.
Changes in new version:
In the latest version of Order Delivery Date, we have removed 2 of these ajax calls i.e orddd_get_zone_id and check_for_time_slot_orddd . The third one i.e orddd_update_delivery_session is converted to WC Ajax and is only called when category based custom settings are applied on checkout.
orddd_get_zone_id was only required on page load or when a shipping zone was changed on the checkout page so that the custom settings for the default selected shipping method could be applied. In place of ajax, we sent all the default shipping methods of each zone to the JS file and there checked for the matching zone. This resulted in much faster loading of the custom settings.
orddd_update_delivery_session ajax was an admin-ajax in the previous version. admin-ajax should not be used on the frontend of a site as it loads a few other core WordPress files in order to be able to serve the request. We converted this to WC Ajax which is specifically used on front end and is much faster than admin-ajax. To further minimize the use of this ajax, we only call it when category based settings are applied on checkout.
For replacement of check_for_time_slot_orddd , we decided to use REST API in place of ajax calls. We created the REST API endpoints to get the settings as well as to get the available timeslots based on the date. REST API’s improve performance and are much faster than the ajax calls.
Here are the REST API endpoints :
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/12 – this would return the custom delivery settings with id 12.
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/?mode=category&category=<category slug> – this would return custom delivery settings for that category
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/?mode=category&category=<category slug>&shipping_method=<method id> – this would return custom delivery settings for that category & shipping method
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/?mode=shipping_method&shipping_method=<method id> – this would return custom delivery settings for that shipping method
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/?mode=pickup_location&pickup_location=<location id> – this would return custom delivery settings for that pickup location
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/?mode=pickup_location&pickup_location=<location id>&category=<category slug> – this would return custom delivery settings for that pickup location & category name
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/12?date=2020-06-20 – this would return the available time slots for the given date in custom delivery settings with id 12.
- http://tychesoftwares.local/wp-json/orddd/v1/delivery_schedule/12?number_of_dates=10 – this will return the next 10 available dates for custom settings 12
Let’s look at the performance difference in the older version and new version.
Only global settings with time slots:
As you can see, it took 4.88s to load all the ajax calls. The 2 admin-ajax calls run here are orddd_get_zone_id & check_for_time_slot_orddd.
Whereas, if you look at the new version:
It took 3.48s to load and only the REST API call is initiated to check for time slots. There is some difference in the load times and number of ajax calls.
Number of ajax calls earlier: 2
Number of ajax calls from v9.27.0: 1 API call
Custom settings with date & time slots:
As we can see, there is a huge difference in terms of loading of custom settings. The load time in the old version is 7 secs while with the new version, it’s 3.54s. There are a lot of ajax calls when custom settings are loaded in the older version. Whereas in the new version, there is only one API call to fetch the time slots.
Number of ajax calls earlier: 7 – 8
Number of ajax calls from v9.27.0: 1 API call
Global settings with only date:
In the previous version, one ajax was called i.e orddd_update_delivery_session when only general settings were applied. This ajax should have been called only when custom settings were applied.
In the new version, as you can see, there is no ajax call happening when custom settings are not present. And the load time is also lesser.
Number of ajax calls earlier: 1
Number of ajax calls from v9.27.0: 0
Custom settings with only date:
As you can see, even with custom settings enabled with only date, there are lots of ajax calls in the previous version whereas none in the new version.
If custom settings are based on product categories, then there will be one ajax call of orddd_update_delivery_session in the new version.
Number of ajax calls earlier: 7
Number of ajax calls from v9.27.0: 0 or 1
These changes will help in the load time and will improve the performance of the website. And with REST API endpoints, there will be a lot of scope in extending the plugin for the store owners.
Because of the multiple ajax calls, the loader would also hinder a smooth experience of the checkout page. now that won’t be the case.
Call for beta testing of Order Delivery Date 9.27.0
We are looking forward to releasing this update by 2nd week of July. We are also looking for volunteers who could help us test the beta copy of the release. Since it is a major release, we want to test it before doing the stable release. This call is for all our existing Order Delivery Date Pro plugin customers! Hit us up in the comments or drop an email to email@example.com. Rashmi is the Product Lead for Order Delivery Date Pro plugin.