You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-8Lines changed: 33 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,15 @@ Example with a django project
10
10
11
11
During development I simply use django tags like *{% url ... %}* and *{% static ... %}* on my .js and .css files to define dynamic url to views and images of my project. At this point the .js and .css are placed into the templates directory of my app so I can *{% include ... %}* it to my .html templates and have the tags rendered to final urls. Of course the js and css will appear inline with the HTML content. For development I think this is fine.
12
12
13
-
On deploy you usually what all your javascript and styling to be in a external file.
13
+
On deploy you usually want all your javascript and styling to be in a single external file.
14
14
15
15
Here is how this script can help you with that:
16
16
17
17
On my base.html template I usually have something like this:
@@ -29,6 +31,8 @@ On my base.html template I usually have something like this:
29
31
{% include 'message/message.js'%}
30
32
</script>
31
33
{% endif %}
34
+
...
35
+
</head>
32
36
```
33
37
34
38
Then simply put this script on the same directory as manager.py. Edit the script to adjust your paths to settings.py and to every JS and CSS you whant to merge/minify. Like:
@@ -59,7 +63,7 @@ merger = {
59
63
}
60
64
```
61
65
62
-
Here we define a path to the django project and the settings.py file to use while rendering the template tags. *You only need to define those if you have tags inside .js or .css, if you don't then simply ignore both*
66
+
Here we define a path to the django project and the settings.py file to use while rendering the template tags. *You only need to define those if you have tags inside .js or .css, if you don't then simply ignore both*.
63
67
64
68
In this case we have two blocks, *my js* and *my css*.
Ok, this can change on your server but that the overall idea...
99
+
Ok, this can change on your server but that's the overall idea...
96
100
101
+
Also you can use the option *--images* to optimise **all***.PNG* and *.JPG* present on the directory tree starting where you executed this script (usualy your django project root). Like:
102
+
103
+
```bash
104
+
$python jscssmin.py --images
105
+
```
106
+
107
+
This will save a copy of all original images with *".original"* appended to its name and a smaller (hopefully), version will be saved with the original name. This script will ignore every file that already have a *.original* version present. To force this script to process every single file again use the option *--images-full*.
All four functions used above are only helper to call some online minifer api. See below. This script does not minify JS or CSS by itself, so you need to be online to execute this with success.
137
+
117
138
Minifier
118
139
--------
119
140
120
-
This script uses the api provided by http://cssminifier.com and http://javascript-minifier.com/ to minify CSS and JS data. Thanks [@andychilton] for this api.
141
+
This script uses some online api provided by [@andychilton] for all minify action:
0 commit comments