Extending time that content is cached

I am very new to web development and if I am doing something hilarious then please excuse me.
I am a mobile game developer and I have made an html game as a demo for the users who want to get a taste of the game before purchasing my game. And for hosting the game, someone suggested me netlify as it is a champion in the field of web-hosting. But truly speaking,my experience with netlify was very “Painful” (although the deployment was as simple as drag and drop)

My story goes below:-
In my game, there are many different types of file (example like html,css,png,txt). Most important files are text files (.txt) which contain information about game’s level. But the issue is “when the game loads all the files,it simply does not caches them”. Because of which when the game is played, it always tries to fetch the file from the online server which causes lag in the game. And in some critical area because of the lag,my game crashes
So I did a small research on the net and to make the game “cache” all the files, I made a file named “netlify.toml” , and entered the given data:-

for = “/*” # This defines which paths this specific [[headers]] block will cover.
Cache-Control = “public, max-age=1800”

And then saved it in the main directory and then I uploaded my game again.And it solved my issue.Now the game files were getting cached.And the lag in my game disappeared. And I tested my game many times to confirm that whether my issue got solved or not
But my success was short lived
After 3 hours,I just tested my game again, and now again my game was not “caching” the files. It seems that netlify just simply forgot what I did earlier.And my game is lagging again

So,please someone help me on this issue. Thanks in advance

1 Like

Can’t help you, but I saw the title. Indeed, Netlify is crazy good, getting better day by day :smile:

Also, I would love to hear from Netlify to see their point of view on hosting games on Netlify - I would probably go directly for AWS services dedicated to game development :thinking:

1 Like

Hi, welcome to the Netlify community forums! max-age takes a value in seconds, so max-age=1800 only sets a cache for 30 minutes. Try setting it to a longer cache time (the maximum is 31536000).

1 Like

Hi @mayank,

@tomrutgers’s advice above is spot on however I’m dropping by to say that I’ve updated the topic’s title so that other people may find the answers you receive a bit easier :slight_smile:

Tell a lie, I do have some reading material to share!

Check out the “caching static assets” section :point_up: :+1:!

My problem got solved but I mean how ?
I initially deliberately put cache value 1800 as I wanted the game to remain in user’s mobile for 30 minutes.

My game is technically just a website with lots of images. I am more than happy with Netlify.

And last question:-
My game size is 10 MB. Earlier when I used to drag my game to Netlify drag and drop section, it used to take time ( normal time required to upload a 10 MB file) . But later on if I tried to upload my game, the uploading happened in seconds. And the game was working perfectly. Was some caching working in the background ( or something else )

After the 30 minutes, your users will need to grab all of the assets again so it may be a little latent, that’s right. Increasing this time decreases the frequency that users will go and grab the files.

However, requests to the CDN usually take our users half a second. So, if you’re experiencing other latencies, you may want to check out a HAR file or observe the Network tab in your browser’s Dev Tools to see where things hang.

If files don’t change, they’re cached at build time, yes :smile:. Though, this is a different type of caching compared to CDN and browser caching.