The Must Have for WordPress
The Must Have for WordPress
×
  • Home
December 5, 2019
Javascript PHP

Minify and compress Javascript files in PHP

by Martin Jost
No comments
1 min Reading Time
371 Views
5 Score
1 Like
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp

Loading time is an important factor in search engine optimization and for the user experience. Especially for theme developers, it’s important to compress or minimize all embedded javascript files for live use on a web page.

How can I compress Javascript files?

The following PHP function provides an easy way to minify javascript without doing it manually. A compressed file version of the original Javascript file could be easily stored in a temporary folder and retrieved if the file exists. This saves a lot of javascript code and a considerable file size.

How do we use the Javascript compression function?

The function minify_js( $file_content ); ensures that all unnecessary tabs, spaces, breaks, and comments are removed within the Javascript file. As result, we get a compressed and minified version of the file content.

Last updated: December 5, 2019

Minify and compress Javascript files in PHP Score: 5 / 5 (1vote)
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp
The Author
Published by
Martin Jost

View all posts by Martin Jost

Related Posts
M
CSS Minify or compress CSS in PHP

For developers of plugins or themes, it is important to provide the included CSS (stylesheets) f ...

Read More
C
Database Create a connection to WordPress MySQL database in PHP

WordPress stores all the website data in a database and uses it, for example, if a certain conte ...

Read More
G
PHP Get Metadata from WordPress Video and Audio files

In addition to images, videos and audio files are other formats that we can upload to WordPress ...

Read More
Read more
C
Previous Post
Convert HEX color to RGBA color code in PHP
M
Next Post
Minify or compress CSS in PHP
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Imprint
  • Privacy Policy
© 2016-2021 - wphave - The Must Have for WordPress
Login

Lost your password?

RequiredEssential cookies enable basic functions and are necessary for the proper functioning of the website.
  • Name: Cookie Status
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user's web browser allows cookies.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookie_status
  • Duration: 1 Minute
  • Name: Cookie Consent
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user agrees to allow opt-in cookies or not.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookieconsent_analytics, cookieconsent_marketing, cookieconsent_status
  • Duration: 1 Year
  • Name: Like Button
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already gave a like for a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): like_btn_{POST_ID}
  • Duration: 21 Days
  • Name: Post Rating
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already rate a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): rating_{POST_ID}
  • Duration: 7 Days
AnalyticsStatistics cookies collect information anonymously. This information helps us to understand how our visitors use our website.
  • Name: Google Analytics
  • Provider: Google LLC
  • Purpose: Google cookie for website analysis. Generates statistical data on how the visitor uses the website.
  • Privacy Policy: https://policies.google.com/privacy
  • Cookie Name(s): _ga, _gat, _gid
  • Duration: 2 Years