Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minifying and Obsfucating CSS similar to Javascript [closed]

I know there are several tools out there that are capable of obfuscating JavaScript files such as by turning a simple functions like:

function testing()
{
  var testing;
  var testing2;
  alert(testing+testing2);
}

into

function a(var a,b;alert(a+b);)

My question is does something like this exist for use with CSS/HTML (or is there a tool that has a similar effect)? In particular, a minification/obfuscation tool that actually renames variables and refereneces and eliminates additional white-space etc.

And if so - would the benefits in performance outweigh the readability in both CSS/HTML/JavaScript minification/obfuscation?

like image 361
Rion Williams Avatar asked Jan 04 '11 20:01

Rion Williams


People also ask

What does Minifying CSS mean?

What is CSS minification? CSS minification is the process of removing unneeded code from CSS source files, with the goal of reducing file size without changing how the CSS file executes in the browser.

How do you minify CSS and JavaScript?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

Should I minify CSS and JS?

Should I Minify CSS and JS. Generally, the CSS and JS files of dynamic websites don't change very often so they are considered static files. Therefore, you can minify those CSS and JS files once and keep reusing those minified files.

How does Minifying a file CSS JS HTML help?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.

How to minify CSS/ JavaScript?

Removing whitespace, shrinking of variable and function names are all common minification approaches. When responding to web requests, the web server utilises the minified file, resulting in decreased bandwidth use without losing functionality. There are a lot of free and easy online tools can quickly minify CSS/ JavaScript.

Should I minify my JavaScript and CSS files for SEO?

Page speed is an SEO ranking factor, and minifying your Javascript, and CSS files can help improve your site’s loading speed and your Core Web Vitals performance. Minification involves reducing the redundancies of a file that aren’t crucial for the file to execute.

What is a minification/obfuscation tool?

In particular, a minification/obfuscation tool that actually renames variables and refereneces and eliminates additional white-space etc. And if so - would the benefits in performance outweigh the readability in both CSS/HTML/JavaScript minification/obfuscation?

What is the best JavaScript minification tool?

Closure Compiler is Google’s JavaScript minification tool that optimizes your code as well. It’s a solid option to consider that parses, and analyzes JavaScript, rewrites code when needed, then minifies after that. It also checks for syntax, variable references, and types as well as warns you of typical JavaScript errors.


2 Answers

It is very difficult to 'minify' HTML or CSS because all that can safely be saved is white space (which doesn't amount to a huge saving). As for class renaming, you loose an important part of the web which is having semantic code (which represents meaning). I think the best option is to ensure that you have gzip compression enabled on your web server and focus on combining your assets into a single file wherever possible.

like image 122
Kevin Sylvestre Avatar answered Nov 09 '22 14:11

Kevin Sylvestre


HTML Muncher is a python tool that tries to rename IDs and CSS class names across HTML, javascript and CSS files. You can use it as a first step in your optimization process, before passing the files to other tools such as Google Closure Compiler or YUI CSS Compressor.

like image 32
zah Avatar answered Nov 09 '22 14:11

zah