order of loading css-files

23 views
Skip to first unread message

Kai Kobschätzki

unread,
Jul 2, 2019, 8:14:38 AM7/2/19
to django...@googlegroups.com

Hi:

I tried to load bootstrap and an own css-file. But in which order does django load it?

I have tried in my base.html:

<!DOCTYPE html>
<html>
{% load static %}
<head>


    <link rel='stylesheet' href="{% static 'bootstrap/css/site.css' %}">
    <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">

    <link rel="stylesheet" href="{% static 'css/base.css' %}">

    <title>{% block title %}gyousei{% endblock title %}</title>


</head>
...

and the log is writing:

[02/Jul/2019 11:54:38] "GET / HTTP/1.1" 200 6259
[02/Jul/2019 11:54:38] "GET /static/css/base.css HTTP/1.1" 304 0
[02/Jul/2019 11:54:38] "GET /static/bootstrap/css/site.css HTTP/1.1" 404 1690
[02/Jul/2019 11:54:38] "GET /static/bootstrap/js/jquery.min.js HTTP/1.1" 404 1702
[02/Jul/2019 11:54:38] "GET /static/bootstrap/js/popper.js HTTP/1.1" 404 1690
[02/Jul/2019 11:54:38] "GET /static/bootstrap/js/popper.js HTTP/1.1" 404 1690

and if I write 


<!DOCTYPE html>
<html>
{% load static %}
<head>

    <link rel="stylesheet" href="{% static 'css/base.css' %}">

    <link rel='stylesheet' href="{% static 'bootstrap/css/site.css' %}">
    <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">


    <title>{% block title %}gyousei{% endblock title %}</title>


</head>
...

the log writes

[02/Jul/2019 11:54:11] "GET /static/css/base.css HTTP/1.1" 304 0
[02/Jul/2019 11:54:11] "GET /static/bootstrap/js/jquery.min.js HTTP/1.1" 404 1702
[02/Jul/2019 11:54:11] "GET /static/bootstrap/js/popper.js HTTP/1.1" 404 1690
[02/Jul/2019 11:54:11] "GET /static/bootstrap/css/site.css HTTP/1.1" 404 1690

If I understand it correct in both cases django loads my base.css first so bootstrap overwrites it.
How can I change this?

Thanks for your response,

bengoshi
-- 
herz-jesu-jugend.de

Jani Tiainen

unread,
Jul 2, 2019, 8:35:23 AM7/2/19
to django...@googlegroups.com
Hi.

It's your browser not Django. Django just emits HTML that is parsed by your browser.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d6be7f83-ca64-cd9d-b72e-2b9a4aa093cb%40herz-jesu-jugend.de.
For more options, visit https://groups.google.com/d/optout.

Kai Kobschätzki

unread,
Jul 2, 2019, 9:15:32 AM7/2/19
to django...@googlegroups.com

Hi,

thanks for your responses. Damn, but learning something new. Is there something existing like a "proxy" in django which deliver the browser only one css (quasi a mixture of all css-files)?

bengoshi

Joe Reitman

unread,
Jul 2, 2019, 9:38:50 AM7/2/19
to Django users
You have a 404 error meaning the browser can not find the file on the server.
The 304 error code means the file is already loaded in the browser and is the same as the file on the server so it won't be modified.

Andréas Kühne

unread,
Jul 4, 2019, 7:30:28 AM7/4/19
to django...@googlegroups.com
Hi,

First of all - if you have 404's you won't load your files in any way - you need to resolve that.

Second the loading of the CSS files doesn't  actually matter - it's the order in which they are in the file that they are added to the DOM. So if you first have bootstrap and then your own CSS you are fine.

Finally - the default way of loading CSS / JS files is that a browser only loads a certain number of files from one domain at the same time (it was previously 2, don't know if that has changed), so files will be put on hold until the first 2 have been loaded, then the next 2 and so on.

The main point here is that if you add the css files in the order you want them to be applied, you are fine.

Regads,

Andréas


Reply all
Reply to author
Forward
0 new messages