[PATCH 1/5] static: added JS Cookie Library to get csrftoken for fetch requests

Jonathan Nieder jrnieder at gmail.com
Wed Jul 21 10:23:55 AEST 2021


Raxel Gutierrez wrote:
> Jonathan Nieder wrote:

>> How do we decide between this going in lib/packages/ versus
>> htdocs/js/?
[...]
> I'm not sure what the htdocs directory is intended for exactly. It
> seems like static files. But this is a good question to ask given that
> there seems to be overlap. I'm not sure what exactly differentiates
> the intended contents of these two directories.

Amplifying this question for others on the list more familiar with
patchwork's intended source layout.

[...]
>> Raxel Gutierrez wrote:

>>> @@ -21,6 +21,7 @@
>>>    <script src="{% static "js/bootstrap.min.js" %}"></script>
>>>    <script src="{% static "js/selectize.min.js" %}"></script>
>>>    <script src="{% static "js/clipboard.min.js" %}"></script>
>>> +  <script src="{% static "js/js.cookie-2.2.1.min.js" %}"></script>
>>
>> Should this use an unversioned URL like the rest of these?
>
> The version is specified in the htdocs/js README, so perhaps it would
> be nice to stay consistent and remove it? However,
> jquery-1.10.1.min.js would continue to break this consistency, so I'm
> not sure about what's right.

Unversioned feels a little cleaner.

(Side note: it looks like version 3 supports ES modules:
https://github.com/js-cookie/js-cookie#direct-download.  That's
probably not enough reason to use a prerelease snapshot of it,
though.)

>> Also, how do we decide between putting this in base.html (i.e., all
>> pages) versus specific pages making requests that need a csrf token?
>> The script is small enough that it shouldn't make a difference, but
>> asking anyway because I am curious.
>
> Personally, I think adding those dependencies in the base.html makes
> it easier later when creating new templates as you don't have to
> remember which one to add as the number of them continues to grow.

Fetching the library is not likely to make much difference because the
browser will cache the js.  But parsing and running it adds a bit to
page load time.  Probably not enough to be noticeable.

> Also, I think following the mindset that more content should be
> handled dynamically client-side with JavaScript means that more
> templates will be using the library. Actually, I think all of them
> should eventually be using it.

Yes, that makes sense to me, so looks good.

Thanks,
Jonathan


More information about the Patchwork mailing list