L
L
logos72016-06-12 21:49:20
Django
logos7, 2016-06-12 21:49:20

How to optimize RequireJS modules in Django project?

Good afternoon!
The problem is this.
There is a Django project whose js modules are written using RequireJS.
Two js scripts are connected to the main page of the project:

<script data-main="{% static "js/main" %}" src="{% static "js/require.js" %}"></script>
<script src="{% static "js/config.js" %}"></script>

main.js contains the common code for the entire project. The remaining modules are written depending on where they are needed in the templates:
#tempate.html
{% block content %}
.....
.....
<script>require(['module_carousel']);</script>
{% endblock %}

This approach solved the problem of dynamic loading of js scripts. Now the question arises how to optimize all this to the maximum. The r.js optimizer - collected all my modules into a single file, and now I have no idea how to connect it correctly so as not to break the site. Each template needs its own specific module, and a single module file breaks everything and refuses to work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-06-13
@logos7

logos7 : there is no ideal
Once again - you need to understand what your problem is and whether it exists at all
Two extremes
1) decompose everything into modules and load as pages open
2) put everything into one file and load it at the first start
And it all depends on your audience and its behavior
About compression
If you already have uglify js or something like that installed and compression is enabled on the server by 9, then you have already done 20% of the work, which gave 80% performance
Further, nothing will depend on janga at all (unless REST API) - frontend things will work further

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question