Slow loading of files into Static folder in Django

Asked

Viewed 122 times

0

I am learning Django and I noticed that the static files take time to load, example; I have a css file that defines the style of the home, I change the font color and update the page and nothing happens, after 2 minutes the font color changes. This is normal in Django?

  • Very difficult to answer without seeing the code because it depends a lot on what your application is doing, for example, if you are only displaying an html to the user this is not normal, however let’s assume that you were creating a Learning machine API, Django would need to load your entire template and then display the page with the changed font. The important thing is that you check the logs on your terminal when you finish making a change and check whether the delay is plausible based on what is being displayed to you.

  • I am not using any API, just loading a simple page. In the terminal, appears this: [16/Jul/2019 12:40:29] "GET /static/css/styles.css HTTP/1.1" 304 0 appears in the color blue.

1 answer

1


Eudson, when accessing and viewing the 304 code, means that the file has not been modified, for this reason, is loaded what is cached, when this occurs, just press Control + F5, this will load all the files from your site again, causing the style.css file to be loaded again, by doing this you will see code 200.

  • This solved the problem, but did not understand this part of "file was not modified", I modified the static file, the page should update automatically. But she carried the changes with delay.

  • 1

    Files loaded in the browser are stored in the cache, this happens a lot with images and css, if you replace one image in the Static folder with another without renaming, for example, when updating the page, it will load the old image. The css files are also cached, for this reason, when you press F5, you read what is in the cache, when you press Control + F5, you ignore what is in the cache and a new copy is "downloaded" from the local server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.