I have a flask app that I am deploying to google app engine.
I have been making changes to the js and css scripts in this app and deploying the updated repository to gae. However, when I reload the *.appspot.com
url after deploying, the js and css files that are loaded in my browser are not the latest versions.
I am unsure of how to solve this. I don't know whether it is a caching issue in my browser, a problem with my app.yaml
file or something else altogether.
When I look in the app engine at the deployed files, the css & js are the current versions that should be being loaded in the browser but aren't.
Here is my app.yaml
:
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: ssl
version: 2.7.11
handlers:
- url: /.*
script: app.app
I'm fairly new to gae. If anyone has any suggestions that'd be great.
Thanks!
UDPATE:
I've added to my app.yaml file according to the suggestion of @GAEfan and the page @Dave W. Smith linked to so that now it looks as follows:
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: ssl
version: 2.7.11
handlers:
- url: /.*
script: app.app
- url: /static
static_dir: static
expiration: '10s'
However the problem persists. I now expect it might have something to do with @Dave W. Smith's other suggestion, that there are "old instances serving requests until they die off."
Here is another screenshot from the GCP platform showing that there are multiple instances of my app running, one from each new deploy command:
The latest version is the default one and the screenshot shows that 100% of traffic allocation is on that version. Should I be deleting old versions of the app everytime I deploy? If so, can this be done with the gcloud
cli? Is there a way I can keep these older versions and just ensure that static files are definitely served from the latest version?
Thanks again.
Yes, sounds like a caching issue. Read this: https://cloud.google.com/appengine/docs/standard/python/config/appref#static_cache_expiration
You can test by setting a small cache time for your static files, like this:
- url: /static
static_dir: static/
expiration: '10s'
Or, even more granular by:
- url: /static/css
static_dir: static/css/
expiration: '10s'
- url: /static/js
static_dir: static/js/
expiration: '5m'
Or globally by:
default_expiration: '2s'
Then, when you are satisfied with your static files, set the cache time to something much higher, to speed up your site and save server time.
If that's your app.yaml
, you might think you have static files, but they're being served by the app. To make that static really static, you'll need bit extra in our app.yaml
. See https://cloud.google.com/appengine/docs/standard/python/getting-started/serving-static-files
What you're probably seeing, unless you're bumping the version for the command line, is old instances serving requests until they die off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With