All Collections
Getting Started
Welcome to NitroPack!
How to Integrate NitroPack Using SDK
How to Integrate NitroPack Using SDK
Updated over a week ago

Important: We currently provide limited support for PHP SDK websites.

NitroPack can be easily integrated with any PHP-based website through our SDK. Here’s how to do it.

After purchasing your NitroPack subscription, you will be automatically redirected to your dashboard from where you should:

  1. Download the NitroPack PHP SDK.

  2. Unzip and upload it to your site in a directory of your preference.

Most frameworks have a vendor directory suitable for adding third-party SDKs. For example, the CodeIgniter framework has a folder for third-party applications: /application/third_party.

  1. Next, go to Cache Settings >> General >> API Keys and copy your API credentials (API Key & API secret key):

  1. Then, load your site's index.php file (or the file that will be used when loading your pages).

  2. Change the values in this line of code with your URL, site ID, and site secret:

define("NITROPACK_HOME_URL", "Your home page URL"); 
define("NITROPACK_SITE_ID", "your site ID");
define("NITROPACK_SITE_SECRET", "your site secret");
include_once "<path to the sdk>/bootstrap.php";

Note: We recommend loading the SDK as early as possible. In many cases, the index.php file is the best candidate. Placing the SDK at the beginning of your site’s code means NitroPack can serve optimizations immediately.

That’s it. The bootstrap file should now be connected to NitroPack and start handling optimizations. You can configure your preferred optimization mode and settings from Settings:

Exclude paths from your version control system

The SDK will store its config and cache files in <path to the sdk>/NitroPack/SDK/data/ and it will also create an empty nitropack_webhooks file at <path to the sdk>/nitropack_webhooks.

It is recommended that you exclude these paths from your version control system. For example, in Git, you can add them to the .gitignore file.

If your site has a login system and you need to disable caching for logged-in users, you can:

1. Load the SDK only when the visitor is not logged in.

2. Configure your site to set a cookie whenever a visitor logs in and remove the said cookie upon logging out. Then configure this as an “Excluded cookie” in your NitroPack settings.

The second option is typically faster because it doesn’t require your application to start a session or open DB connections.

How to set URL tagging for dynamic sites

The basic SDK integration is great for static sites, which are rarely updated. However, dynamic sites like media outlets and e-commerce typically need to be able to purge specific parts of their cache instead of the entire cache.

NitroPack achieves this through URL tagging.

You can assign one or more tags to a page. Then, you can purge the cache only for pages containing the specific tag.

For example, you can tag your home page with “page:home”, your category pages with “page:category”, product pages with “page:product” and so on.

You can also add tags for specific items. For example, a product page might have a tag “product:128”, so you can then purge that product’s page whenever you update the product in your system.

Tags must follow the naming rules described in our API documentation.

Adding tags can be done with the helper function nitropack_add_tag($tag)

Purging the cache

There are two ways to update your cache:

  • Purge - can be done with the nitropack_sdk_purge($url, $tag, $reason) function

  • Invalidate - can be done with the nitropack_sdk_invalidate($url, $tag, $reason) function

Purge deletes the cached file from your site, meaning your site visitors will immediately see the updated content. Invalidate only marks the cached content as "stale" but keeps serving it until newly optimized content is available. You can read more about it in our article.

In both cases, you can update the cache by providing a URL, a tag, or both. If none is provided, the entire cache is going to be updated.

In the $reason parameter, you can insert a human-readable message describing the reason for the purge. This goes into the Service Usage Logs, so you can later review the behavior of your integration.

📌 If you need any assistance or have questions, you can contact our Support team using the chat bubble on the bottom right of this page.

Did this answer your question?