0

This is more of a "why does this happen" kind of question, as it isn't a big deal. It would be great to have it stop, but I'm OK with it sticking around.

I have a webapp I made with Django. I have two servers: a development server and a production server. I have all the CSS/img/js files loading correctly and everything works fine on both servers. Sort of. The production server is working flawlessly (everything loads as it should for CSS/imgs/Javascript)

I do all my development on the dev server and use Django's test server while I code. When I first do the runserver command, I open up my browser (Chrome, specifically). I navigate to my 192.1.1.123:8080 address and there is my Django web app, but with none of the CSS loaded. What I then have to do is open a second tab (leaving the first open) navigate to my 192.1.1.123:8080 again, and then all the CSS loads (without restarting the django web server). I believe this is a browser trait - something about cache. But I'm not sure.

Any idea as to why this happens?

1 Answer 1

1

I had similar problems when I was working on several Django projects and I was switching between them. The browser cached all static content and didn't noticed that the file changed by switching to another project. Reload the page with CTRL+F5 should solve it.

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

4 Comments

Thanks for your response. I see that CTRL+F5 does solve the non-loading CSS, but I guess I'm wondering if there is a way to make it not happen in the first place. Is that a browser problem and, well, there's nothing that can be done?
I don't see how this is a problem? It should only happen the first time you load your site locally. It makes perfect sense why it's happening; the browser thinks it already has the CSS cached. You could add headers when in development to instruct the browser not to cache or you could use an incognito window, but I think it's easiest to just CTRL+F5
Ya, agreed. It's not a problem and, yes, I do just hit CTRL+F5 as you suggested. I was more thinking about what is going behind the scenes for learning, and how one might prevent this from happening. Since this is a browser 'issue' I don't see a way to prevent it from happening.
You should just disable cache from chrome dev tools. I can't tell you how many times a cache issue has... caused me problems / hidden a fix or problem.

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.