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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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