A different method for generating unpredictable dynamic URLs using JavaScript/prevent wpengine from caching

When integrating a PHP file from a wpengine site into a bigcommerce (formally interspire) platform, the inclusion process appears as:

%%Include.http://www.server.com/testing.php?store_id=4649b4c235fba82029176fa8a802c3%%

To learn more about this process, click here:

While everything functions properly, an issue arises with the clock within the included file updating every 20 minutes instead of every minute due to wpengine's own cdn delivery. Attempts to reset the cache by modifying the URL are successful, such as changing it to include different variables like

%%Include.http://www.server.com/testing.php?store_id=4649b4c235fba82029176fa8a802c3&variable=123456789%%
and
%%Include.http://www.server.com/testing.php?store_id=4649b4c235fba82029176fa8a802c3&variable=987654321%%
.

However, when trying to introduce dynamic variables through JavaScript like:

<script>
variable = Math.floor(Math.random() * 1000) + 1;
document.write("%%Include.http://www.server.com/testing.php?store_id=4649b4c235fba82029176fa8a802c3&variable=" + variable + "%%");
</script>

The intended functionality fails, leaving uncertainty in diagnosing the issue. Although the correct file and store_id are present, the dynamic variable fails to affect any changes.

Are there any alternative methods for introducing a dynamic variable or preventing the cdn from caching the page?

Answer №1

If you're using this in BC, try adding the cache busting string that BC uses on some of their JS files. It typically includes a date/timestamp.

%%Include.http://www.server.com/testing.php?store_id=4649b4c235fba82029176fa8a802c3&variable=%%GLOBAL_JSCacheToken%%%%

I haven't personally tested this method before, but I hope it proves to be effective for you!

Answer №2

Consider reaching out to WPE assistance for help in removing the store_id parameter from the cache settings.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can you achieve the same functionality as running multiple instance methods in functional programming using JavaScript?

Let's consider a scenario where we have a JS class with Typescript defined as follows: type Command = 'F' | 'B' // Forwards, Backwards class Car { private x: number private y: number constructor(x: number, y: number) { ...

Discovering the screen dimensions or viewport using Javascript in Bootstrap 4

Is there a method to identify the view port/screen size being utilized by Bootstrap 4 using Javascript? I've been struggling to find a dependable way to determine the current view port after a user resizes the browser. I attempted to use the Bootstra ...

Is it possible to utilize viewport height as a trigger for classes in Gatsby?

Unique Case Working on a Gatsby site with Tailwind CSS has brought to light an interesting challenge regarding different types of content. While the blog pages fill the entire viewport and offer scrolling options for overflowing content, other pages with ...

Implementing one-to-many relationships using Knex.js and Bookshelf.js in an ExpressJS/Postgres environment

When a user registers, I want to create a record on two tables simultaneously. user.js const db = require('../database'); const User = db.Model.extend({ tableName: 'login_user', hasSecurePassword: true, hasTimestamps: true, t ...

What is the best way to add a div container to a particular section of a webpage?

I have come across many solutions that involve using JQuery, but I am specifically looking for a pure JS method. Currently, I create a div, add content to it using Create Element and innerHTML, and then use appendChild to place it at the bottom of the body ...

"Exploring Browser Performance: An Insight into Display and Visibility

As I design my portfolio website, I've included a horizontal slider to showcase each piece of work. Imagine having 100 graphically intensive or flash objects in total. In this setup, only up to 4 works can be visible on the screen simultaneously. Al ...

Identifying Regex patterns within the className attribute of a React/jsx component

Below is a snippet from my React component <div className="grid lg:grid-cols-2 xl:grid-cols-1 lg:gap-x-5"> <article className={`${index > 0 ? 'border-t lg:border-t-0 xl:border-t border-gray-300/70' : ''} py-8 sm: ...

Encountering a challenge in Angular 8: Unable to locate a supporting object matching '[object Object]'

I am having an issue trying to retrieve the Spotify API from the current user's playlists. While I can see it in my console, when I attempt to insert it into HTML, I encounter the following error: ERROR Error: Cannot find a differ supporting object ...

Tips for showing a different div in the chat window after submitting the form

My index html file features a chat window designed like this: https://i.sstatic.net/PPGoy.png Below the submit button is an area to input text. How can I hide or disable this section and enable it only after the form is filled and the submit button is cl ...

Readiness of Ajax onreadystatechange function state

I have a script that fetches raw JSON data for an image from Flickr and displays it on the page. I want to provide real-time feedback using readyState during the process. Currently, my code checks if the readyState is 4 and the status is 200 before adding ...

Showing JSON information in an Angular application

Upon page load, I am encountering an issue with retrieving and storing JSON data objects in Angular scope for use on my page and in my controller. When attempting to access the value, I receive the error message: angular.js:11655 ReferenceError: data is ...

Interacting with the Chrome Password Storage Menu while leaving the mouse

Implemented an OnMouseLeave property in this menu to automatically close when user moves away from the menu space, which is working well. However, since it's a login form menu, clicking on input fields triggers Chrome's password manager to sugge ...

Looping in PHP with Ajax to trigger a flush operation

I apologize for asking the same question again, but the solutions provided are not working for me. Currently, I am using Ajax to execute PHP code after a button click and ob_flush() to flush out the echo statements one after another. However, all my echos ...

Trouble Connecting Local Database with PG NPM Package

I'm encountering issues with using the pg package on my computer. I've attempted to execute the following code: var pg = require('pg'); var con_string = "postgres://user:password@localhost:5432/documentation"; var client = new pg.Clie ...

The AngularJS controller is triggered twice

I'm facing an issue where a controller seems to be executing twice, even though I cannot find any duplicates in my files. Running a case sensitive search through my code only reveals one instance of the controller in route configuration and the actual ...

Choosing bookmarkable views in Angular 5 without using routes

I'm currently working on a unique Angular 5 application that deviates from the standard use of routes. Instead, we have our own custom menu structure for selecting views. However, we still want to be able to provide bookmarkable URLs that open specifi ...

After using driver.execute_script, the variable results in nil

Attempting to retrieve a lengthy string of URLs separated by commas is proving challenging. The code functions correctly in the console, but when running the script, the ruby variable urls_list remains nil. require 'rubygems' require 'selen ...

Adding JSON data to an array with a click - a step-by-step guide

As I dive into working with React and integrating API JSON data into my project, I've encountered a small hurdle. I've implemented a function that allows users to enter a search query, resulting in a list of devices associated with their input be ...

How to display a variable within a button group to impact a dropdown selection in Angular.js and HTML

Here is where I am at with my current project: <div class="container" ng-app="app" ng-controller="dataCtrl"> <h2>Test</h2> <h4>Choose a Category</h4> <ul class="nav nav-pills"> <li ng-repeat="cat ...

What factors should I consider when choosing the appropriate socket for receiving messages from a RabbitMQ queue?

I have encountered an issue while trying to connect to a queue on a remote server using Rabbit.js. Every attempt to connect results in the following error message: Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITI ...