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
3.51 K Views
3 Score
2 Likes
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: 3 / 5 (2votes)
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
R
WordPress Remove date / time from WordPress comments

By default, the date and time of a comment are displayed in WordPress. Basically, it is always a ...

Read More
C
PHP Customize the default WordPress Image Compression

WordPress uses its own compression for images that are uploaded directly into WordPress. This ha ...

Read More
A
WordPress Add custom classes to the WordPress BODY tag

Anyone who develops their own theme with a customizable layout or settings a theme needs to add ...

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-2023 - 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