Loading all js and css at login

24 views
Skip to first unread message

Larry Martell

unread,
Oct 1, 2013, 11:08:07 AM10/1/13
to django...@googlegroups.com
I would like to load all the javascript and css files that my app needs when the user logs in. So I added lines like this to my login.html:

<link rel="stylesheet" href="/static/style/tablesorter.css" type="text/css" />

<script src="/static/scripts/jqplot/jquery.jqplot.js" type="text/javascript" ></script>

But when I go the pages that need these (that used to include them in their templates), they don't seem to be available. I don't get any errors, but it's clear that the js is not running and styles are not being applied. Am i doing something wrong? How I can load everything at login time?

TIA!
-larry


Bill Freeman

unread,
Oct 1, 2013, 11:23:56 AM10/1/13
to django-users
While the browser may cache this stuff, images too, from the browser's point of view, if you are on a different page, you don't have access to stuff the login page loads.

What does help is to always use exactly the same URL for the static media, in which case when a page calls it out, the browser can realize it has that CSS, JS, etc, cached, rather than downloading it again.


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY5SguJjgvP%2Bw%3DQu4vi1zNkB%2BnSiKaNAw_FeCUbSr%3Dm_RQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Larry Martell

unread,
Oct 1, 2013, 11:44:28 AM10/1/13
to django...@googlegroups.com
On Tue, Oct 1, 2013 at 9:23 AM, Bill Freeman <ke1...@gmail.com> wrote:
While the browser may cache this stuff, images too, from the browser's point of view, if you are on a different page, you don't have access to stuff the login page loads.

Ah, thanks. I did not know that. I put back the js and css references into the individual templates and it's working now. I verified in the Chrome debugger that they are being loaded from the cache. 
 

What does help is to always use exactly the same URL for the static media, in which case when a page calls it out, the browser can realize it has that CSS, JS, etc, cached, rather than downloading it again.


On Tue, Oct 1, 2013 at 11:08 AM, Larry Martell <larry....@gmail.com> wrote:
I would like to load all the javascript and css files that my app needs when the user logs in. So I added lines like this to my login.html:

<link rel="stylesheet" href="/static/style/tablesorter.css" type="text/css" />

<script src="/static/scripts/jqplot/jquery.jqplot.js" type="text/javascript" ></script>

But when I go the pages that need these (that used to include them in their templates), they don't seem to be available. I don't get any errors, but it's clear that the js is not running and styles are not being applied. Am i doing something wrong? How I can load everything at login time?

TIA!
-larry


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY5SguJjgvP%2Bw%3DQu4vi1zNkB%2BnSiKaNAw_FeCUbSr%3Dm_RQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages