Passing files to JavaScript

Very small shoutout – don’t try to make relative path work.

Don’t every do this:

img = '../../static/image/kek.png';

In any form! Like this either:

img = '../{% static 'image/kek.png' %}';

You either do this altering static_path on different pages:

static_path = '../../';
file = '{% static 'image/kek.png' %}';
img = static_path + file;

And make your JS dude use them too (make them run their scripts from a separate file).

Or do absolute paths:

img = '/static/image/kek.png';

But it won’t work for your JS dude, oops.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.