Welcome folks today in this blog post we will be compressing
or minifying
javascript file using javascriptminifier
api in python. All the full source code of the application is given below.
Get Started
In order to get started you need to create an app.py
file and copy paste the following code
But before that just create a index.js
file inside the root directory and copy paste the following code into it
index.js
1 2 3 4 5 6 7 8 9 |
alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") alert("hi hello") |
app.py
1 2 3 4 5 6 7 8 9 |
import requests url = 'https://javascript-minifier.com/raw' data = {'input': open('index.js', 'rb').read()} response = requests.post(url, data=data) f2 = open("index.min.js", "w") f2.write(response.text) f2.close() |
And now inside this python snippet we are taking the input javascript file and then if you execute
python script it will compress and minify it and then it will create the output file inside the root directory
python app.py
After this you will find the output file created which is minified as shown below