In this article, I am giving a tip to how to create cache files quickly on the WordPress hosting server and CDN. No matter which cache plugin you are using or which CDN service.
You are using a cache plugin in WordPress to create static files for your dynamic content to increase performance. Also, maybe you are using a CDN for your WordPress blog. But suppose you have made some changes in your theme and now you need to clear all the cache files on your WordPress hosting and on your CDN as well so that users can see the changes you have made.
When I had to do this, it really gives pain to me, because it decreases the performance of my website for a while or for a few days. Because a cache file will be created especially on CDN when the first time a user opens a specific page. Then the next user will be served by that cache page if he/she requests the same page.
Then I was trying to find the way to how to create cache files quickly so that every user served fastly by the cache page. And what I found is the
To test, after deleting the cache from hosting server and from the CDN, I fetched a page from my website using the following command:
curl -svo /dev/null https://www.foxinfotech.in/2019/05/dbms-output-package-in-oracle.html
First time I got the
cf-cache-status: MISS. Then when I executed the same command again, I got the
cf-cache-status: HIT. It means the cache file for the above page has been created on the WordPress hosting server and the CDN as well.
Then I thought that if I execute this command for all URLs (means all pages of my WordPress blog), then the cache files could be created quickly. So I used the following approach to do this.
Create Cache Files Quickly on WordPress Hosting Server and CDN
Create a text file containing all your website URLs. How to do this? The answer is to use your sitemap. Open your sitemap on a browser, for example, https://www.yoursite.com/post-sitemap.xml. Then copy all the URLs and paste it into a text file. Make sure that your text files should look like as shown in the below example:
Now on windows, create a batch file as shown in the below example:
@echo off for /f "tokens=*" %%a in (myurls.txt) do ( echo %%a curl -svo /dev/null %%a ) pause
Now run the file by using the following steps:
- Open the Command Prompt on Windows.
- Move to your folder in which you created above two files — for example,
- Then type the batch file name to execute it — for example,
It will run the above program and will fetch every URL exists in the text file
While the program is running, you can check your cache files location on your WordPress hosting server. For example:
You will start finding all the files which are being crawled by the
Script for the Mac and Linux Systems
To run the curl command on Mac or Linux system, create the shell script as shown in the below example:
#!/bin/bash input="myurls.txt" while IFS= read -r var do curl -svo /dev/null "$var" done < "$input"