I have a Django application in app platform. After I run collectstatic (even if the bucket is empty), older versions of my static files are being uploaded to spaces.
I see the latest files in my Github repository and it’s set to autodeploy. I see the right files in my static folder on app platform via the console (/workspace/static). I run collectstatic after deployment is successful and it shows no files need to be updated.
Settings file:
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
AWS_DEFAULT_ACL = 'public-read'
AWS_S3_ENDPOINT_URL = env('AWS_S3_ENDPOINT_URL')
CUSTOM_DOMAIN = env('AWS_S3_CUSTOM_DOMAIN')
AWS_S3_CUSTOM_DOMAIN= '{}/{}'.format(CUSTOM_DOMAIN,AWS_STORAGE_BUCKET_NAME)
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_LOCATION = 'static'
STATIC_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'config.storage_backends.StaticStorage'
PUBLIC_MEDIA_LOCATION = 'media'
MEDIA_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, PUBLIC_MEDIA_LOCATION)
DEFAULT_FILE_STORAGE = 'config.storage_backends.PublicMediaStorage'
PRIVATE_MEDIA_LOCATION = 'private'
PRIVATE_FILE_STORAGE = 'config.storage_backends.PrivateMediaStorage'
else:
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'mediafiles'
STATICFILES_DIRS = (BASE_DIR / 'static',)
I am using the CDN/Edge capabilities and do have CORS headers, but I haven’t had any CORS errors. I purged the CDN cache in spaces multiple times, but it’s the same files every time regardless of deployments.
Does app platform or spaces cache static assets?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
I believe that the App Platform itself doesn’t cache static assets, but Spaces can have caching mechanisms. The CDN/Edge capabilities you’re using might be caching the files.
But also, an important thing your browser might also be caching the files. I could suggest accessing your site in an incognito/private browsing window or after clearing your browser cache.
The fact that
collectstatic
shows no files need to be updated suggests that Django believes the files in Spaces are up-to-date.You can also, double-check that the files in your GitHub repository, local static folder, and the ones in Spaces are actually different. Sometimes, the difference might be in the metadata rather than the content.
Also, you can try running
python manage.py collectstatic --clear --no-input
to force a complete refresh of your static files.Another thing that you can review is your
StaticStorage
class inconfig.storage_backends.py
and make sure it’s correctly handling file updates.As a temporary measure, you could try manually uploading the updated static files to Spaces to see if that resolves the issue. Or alternatively, you could implement a versioning system for your static files. This can be done by appending a query string to the file URLs based on their modification time or a hash of their content.
Let me know how it goes!
- Bobby