One of the primary features of NitroPack is the page caching mechanism. It is used to speed up the response time/TTFB (Time To First Byte). Here is how it works:
A page on your website is visited for the first time. OpenCart runs as usual (executes PHP code, runs and waits for MySQL queries) and generates the needed HTML. NitroPack captures this HTML before it is sent to the client and saves it in a cache file under the system/nitro/cache/pagecache/ directory.
- A consecutive visit (by the same client or anybody else, even bots) to the same page is made, but this time NitroPack intercepts the connection and responds with the cached HTML skipping the time that OpenCart would have otherwise needed to execute PHP, wait for MySQL queries and generate the HTML. This results in a lightning-fast response.
NitroPack page cache is a fast render output cache mechanism that serves already processed content directly to your visitors. The cache is generated per page, meaning that each cache file corresponds to the HTML of a single page. A cache file is created only when a page is being visited for the first time, so if some pages are never visited, they will not be cached. The first page visit is when the cache is created and any consecutive visits are served from the cache. Since the cache is being created on the first page visit, the initial page load could be slightly slower.
The cache is global, meaning that it does not matter which visitor will be the first one to cache a page, all future visitors will benefit from the cache.
Page cache saves the cached content in the following directory:
Your PHP user needs to have write permissions in this directory in order for page cache to be created.
ImportantBefore enabling the NitroPack page cache, make sure that all other third-party page cache solutions are disabled. Otherwise, you might come across unexpected behavior.
To configure NitroPack page cache, visit your OpenCart Admin Panel > Nitro > Settings > Cache Systems > Page cache. You will see the following configuration fields:
1. Page Cache Status (Enabled / Disabled) - This switch controls whether page caching is enabled or disabled.
2. Expire Time (Integer, representing number of seconds) - If the cache files get older than this time period, they will be re-cached automatically. Default value is 86400 which represents 1 day in seconds. It is a common practice to extend this to 1 week or 1 month. The value for 1 week is 604800 and the value for 1 month is 2592000.
3. Responsive theme optimizaiton (Enabled / Disabled) - By default NitroPack creates separate cache files each of the three main versions of your site (Desktop, Tablet, Mobile), because they may have different HTML. If your theme is responsive and you know that the HTML is the same regardless of the device type - Enable this option. It will tell NitroPack that it can use 1 file instead of 3, which saves disk space and CPU time.
4. Add width/height attributes to images (Enabled/Disabled) - Enabling this helps for faster image rendering by your browser. It adds width and height attributes to the <img> tags inside of the cached HTML. This speeds up the rendering time on your customers' browsers.
NoteThis option is not compatible with some OpenCart themes. If your images get stretched because of this option, it is recommended to disable it.
5. Clear cache on product edit (Enabled / Disabled) - When enabled, the page cache for a specific product will be cleared automatically on one of the following conditions:
- After you modify this product from the admin panel
- After a customer purchases this product
- After you edit an order containing the product
NoteYour MySQL user must have CREATE and ALTER permissions in order for this feature to work. If your MySQL user does not have CREATE and ALTER permissions, keep this feature disabled.
If you are not sure whether your MySQL user has the required permissions, simply enable the option and check whether this will generate any error messages. In most cases you will not have issues with this option.
6. Ignored Routes (OpenCart routes, separated line by line) - If you do not want to have page caching for certain routes in your store, list them here. One route per line. Example: common/home
8. Store Front Widget (Show only for admin / Show always / Show never) - This setting controls when to display the store front widget. The widget is a small stripe in the very bottom of the screen, which is displayed for pages that have been served from the cache. It shows useful data like how fast did NitroPack serve the page and how much faster was that compared to the default loading speed without NitroPack. It also allows you to clear the cache for the current page only by clicking the green Clear Cache button on the right side of the widget. Here is how the stripe looks like:
Here is how the options for this setting work:
- Show only for admin: The widget will be displayed only to admins, so regular users will not be seeing it (this is the default setting)
- Show always: The widget will be displayed to everybody
- Show never: The widget will never be displayed
There are some cases, when it would be more beneficial to serve non-cached content to your visitors. In the following cases, NitroPack page cache is deliberately disabled:
If your customer is logged into their account - Page cache needs to be disabled for this case, because almost all of the stores display a different header for each user (containing username, items in cart, etc.).
If your customer has items in the shopping cart - Same as above, having an item in your shopping cart will lead to different front-end content, which is better to remain non-cached.
If your customer has items in the wishlist - Same as in point 1, having an item in your wishlist will lead to different front-end content, which is better to remain non-cached.
If your customer is visiting an ignored route - They can be configured in OpenCart Admin Panel > Nitro > Settings > Cache systems > Page cache > Ignored Routes.
If your customer is visiting an ignored URL - They can be configured in OpenCart Admin Panel > Nitro > Settings > Settings > Disable NitroPack for specific pages.
If Maintenance mode is enabled in your store - In this case, we need to make sure that the Maintenance page will be served to your customers, instead of a cached page.
If the request is AJAX - AJAX requests in almost all cases return different content, which is why they should not get cached. This also allows you to use AJAX to implement dynamic content for cached pages.
If the request is POST - POST requests are used when the client needs to send information to the server which must be processed. This is why we need to let OpenCart handle these requests normally in order to preserve proper site operation.
If the customer has an YMM filter selected - YMM is a third-party module, which allows your customers to filter products based on Year, Make and Model. More information about YMM can be found here: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=3621
- If the customer has AbandonedCarts enabled for his IP address.
Page cache is also automatically disabled for the following routes, since they always display dynamic content:
Pre-caching of content
Because the cache is created on the first page visit, this means that the first visitor for a page will not get the cache benefits like the rest. The NitroPack pre-caching tool is an optional way to simulate the first-visitor of your store to create the cache, so all visitors can benefit from the cache later on. It is not required to run this tool after each clear cache, but when you use it, it will make the cache serving to the first visitor of your store possible, since the cache will be already created for them.
In order to use Pre-cache, please visit OpenCart Admin Panel > Nitro > Settings > Cache systems > Page cache and click the button Pre-cache sitemap pages. The pre-cache process will start afterwards.