Python 3 Script to Minify or Compress Javascript File Using JavascriptMinifier API Full Project For Beginners

Python 3 Script to Minify or Compress Javascript File Using JavascriptMinifier API Full Project For Beginners

 

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

 

 

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

 

 

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

See also  Python 3 Script Kruskal's Minimum Spanning Tree Algorithm Full Example Project For Beginners

 

python app.py

 

After this you will find the output file created which is minified as shown below

 

 

 

 

Leave a Reply