Question

Spaces receives old assets from app platform (Django)

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?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
August 7, 2024

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 in config.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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.