Hi Daniel, This is a separate idea. Instead of relying on JSON dumps, we actually generate an entire JS script via the engine.
The flow is along the lines of: > Client makes request > Django receives request and renders an HTML page which it passes to the client. > The given HTML page has a script tag which requests a javascript file from our server. > Django receives this request and, instead of serving a static javascript file, renders a javascript file via the templating engine which it then passes to the client. This allows us to have more control over the client side scripts based on what is happening server side. It's a bit niche - but it cleared up a lot of the legacy JS held in massive script tags which were overly wasteful and required a lot of tampering based on server side variables. On Tue, Oct 11, 2016 at 3:11 PM Daniel Moisset <[email protected]> wrote: > Hi Nick, I'm not sure what kind of generation are you suggesting. What > I've used a couple of times is creating a template tag to convert a > json-like data structure in the context to a javascript object, so in the > template I have something like this in a <script> tag: > > var foo = {% foo|to_json %}; /* foo comes from python context typically a > compelx nexted dict/list */ > // code that uses the data in foo > > Are you suggesting something like this or something different? > > > > On 11 October 2016 at 14:33, Nick Sarbicki <[email protected]> > wrote: > > Hi Everyone, > > We were tasked at work some time ago with tidying up a legacy Django > project. Part of the projects JS relied heavily on Django variables and > settings and we were seeing frequent large variable JSON dumps in the > templates. > > We cleaned this up and ended up designing a small package which allowed us > to generate Javascript files through the Django templating engine when > requested by the client. > > Since then we've started finding ourselves thinking about using this > package more and more. > > So I was wondering, is this something that the community would be > interested in? It's not open source yet but we're considering opening up > the particular package (not least so its more available for us). > > If it's not at all of interest, why? Is there a big disadvantage to > generating Javascript through the templating engine? (assume you, and not > the client, control the variables going in. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/04d4d42d-3bfa-47c6-9ac7-e9d801de9286%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/04d4d42d-3bfa-47c6-9ac7-e9d801de9286%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > > > -- > Daniel F. Moisset - UK Country Manager > www.machinalis.com > Skype: @dmoisset > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/CALuYSZXsojot-h7sQ4hpRg6UU4Mqjj6HUtfhzzqNoKamRUheTw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-developers/CALuYSZXsojot-h7sQ4hpRg6UU4Mqjj6HUtfhzzqNoKamRUheTw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAGuvt93dQNojNpw%2BGL0zO1UTWZ96yRf_neBauuRNpZV9FPDARg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
