All Collections
General Settings
Dynamic Content Cookies - Create Different Cache Files Based on Your Cookies
Dynamic Content Cookies - Create Different Cache Files Based on Your Cookies
Updated over a week ago

Some plugins may use cookies to set dynamic content or serve different types of information about a user.

For instance, a third-party plugin can set a cookie to detect and store your user’s current geolocation to show them content in a specific language or currency. That can also be combined with several cookies, each responsible for displaying particular data.

Unfortunately, issues can occur if the plugin dynamically changes the content using PHP.

When NitroPack creates an optimization for a page, it takes the current state of how the page looks. That means any PHP code will not execute again; hence, your page's content won't change dynamically. No matter if the cookie is correctly presented, the content on the page will NOT be updated.

Ideally, the plugin of your choice will have the option to enable cache compatibility, which will switch the execution from PHP to JavaScript. This will allow NitroPack to both cache and display the dynamic content accurately.

NitroPack will be able to create different cached files for each HTML variation based on the PHP execution.

For example, if your website has two languages - English and Spanish, NitroPack can create two sets of optimizations for the same page based on the language.

Our team has developed a feature called “Dynamic content cookies” which can be found in the NitroPack DashboardCache Settings -> CacheDynamic content cookies.

How to work with Dynamic content cookies?

There are three fields there:

  • Cookie Name
    Here, you will have to specify the name of the desired cookie.

  • Cookie Values
    Here, you will have to specify all the possible values. They should be separated by commas.
    * The field can also be left blank to catch all possible values

  • Group
    Here, you can combine different cookies in one group. This means you will have only one optimization for each group instead of all possible combinations.

Explanation of each field and how to properly configure them

  • Cookie Name (mandatory)

For NitroPack to start working, you must fill in the Cookie Name field.

  • Cookie Values (optional)

Specifying Cookie Values is not required, but it is highly recommended. Including all possible values ensures that our Cache warmup feature can simulate each scenario and prepare optimizations in advance. If you decide to skip it, an organic visit must occur before our service can detect and optimize that combination.

If you leave Cookie Values empty, our service will create optimization for all encountered combinations.

  • Group (optional)

Using Group is again optional but recommended, especially for bigger websites. By creating different groups, you tell our service that a combination outside these groups cannot occur. This way, you will preserve resources on both our end and your server, as unnecessary cache files won’t be stored.

Here’s a basic example of using Group:

➡️You are a site owner and sell products in Germany and the United Kingdom.

In that case, you will have cookies such as:

Language - English and German

Currency - GBP (£) and EUR (€‎)

You can avoid cache generation for English with EUR or German with GBP. by correctly grouping the currencies and languages.

This may not even be possible for visualization on your website. However, our service will generate cache files for the incorrect combinations, which will use disk space.
This may be ignored in smaller websites with 100-200 pages, as the combination won’t cause that many pages to be generated.

For larger sites with more than 1000 pages, along with several languages and currencies, if the cookies are not grouped correctly, a lot of unnecessary cache combinations will be created, resulting in higher disk space usage.

With the price of a few more clicks, you will ensure that only valuable cache will be generated and stored.

Where can I find more information on my cookies?

The cookie's name and value may differ based on the plugin you use.

The best way to track the cookie name and value will be through the Developer Tools console in the browser.

To open the Developer Tools Console, right-click anywhere on your website’s page and select “Inspect.”


The other way to access the inspector is by going to ViewDeveloper Developer Tools in the Chrome menu bar.


In your DevTools panel, simply navigate to the Application tab. Inside, head to the Storage section on the right side, then Cookies, and select your domain name.


Kindly note that to fetch all cookies used on a page, you will need to refresh the page.

The screenshot below shows an example of several cookies that differ based on the user's geolocation. Some example cookies are:

  • woocommerce_multicurrency_forced_currency

  • woocommerce_multicurrency_language


From this panel, you will be able to obtain the proper name of the cookie and its possible value.

Once you are aware of them, feel free to group them appropriately.

Why am I not seeing the different number of optimized pages?

Our dashboard does not visualize all possible optimized combinations.

No matter the “missing” listing, the pages are getting optimized, and once the optimization is complete, it will be served for the end visitor.

You can also confirm this by checking NitroPack’s Optimization logs. Those can be seen via NitroPack’s DashboardAnalyticsEvents History.

When an optimization is created for a specific set of cookies, the logs will reflect this:

Why is the first visit not served from the cache?

The configuration of the Dynamic content cookies plays a considerable part in the preparation of the cache.

If you have not configured both Cookie Name and Cookie Value, our Cache Warmup won’t be able to prepare optimizations in advance.

In that scenario, a client's first visit won’t be served from the cache. From then on, all other visits will get the optimized version of the page.

Will this method work with server-based cache and Varnish?

Unfortunately, no.

Using that feature requires your PHP code to execute. When you have additional layers of cache that serve pages, there are no PHP executions.

Therefore these features are not compatible with additional layers of cache.

📌 If you need any assistance or have questions, you can always reach out to our support team at [email protected] or via this link:

Did this answer your question?