1

I am writing my first web application using Flask and SQLAlchemy.

My CSS file is currently saved under a static folder and the styling is correctly applied to my webpage

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">

However when I try to update it (for example changing the fontweight from bold to normal) it will not show.

I could even remove all the content of my css file and my website will still look the same (as if the content was never deleted).

The only way I found to make updates was to create a new file "main2.css" and update the url link from the HTML file which is very inconvenient.

Has anyone found a better way?

4 Answers 4

1

It sounds like your CSS file is cached. You can test this by changing 'main.css' to 'main.css?something'. Some people append a date string or other to their CSS file so it busts cache periodically.

Sign up to request clarification or add additional context in comments.

Comments

1

It's possible you're getting the cached version of your CSS. After making updates to your CSS file, have you tried doing a hard reload? How you do this depends on the browser, but for Safari this can be done by holding Shift and clicking the Reload button.

1 Comment

Indeed that's the case! After doing a hard reload I was able to see my updates. Thank you so much for helping!
1

I had the same issues and I realised I couldn’t keep asking my users to do a hard reload. Constantly renaming my static folder (where all CSS/JS files were kept) seemed error-prone from a production devops perspective. Then I found this addon called flask-static-digest, which was adding md5 hashes to the file names as well as gzipping them. It is a good fix for my production server.

https://github.com/nickjj/flask-static-digest

Comments

0

Another solution I found was really helpful during testing is to do a full reload in your browser (in my case Google Chrome) by shift-clicking the reload button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.