Removing Whitespace in coding
-
I consider WP to be great but I do not understand why coders do not remove whitespace from their code before publishing.
Google, Bing, Yahoo and the rest of the search engines are looking for better speed from our sites and although it is a small amount, if coders were to remove whitespace before publishing, across the web this would amount to massive savings.
Come on WP – insist upon it. If we all do it think of the difference it would make.
-
I don’t understand why you’re asking WordPress core and not your theme’s vendors/ developers. Why not just use a minification plugin too?
Let me provide you with an example: –
the “themes-rtl” file in admin/css – before line removal the number of lines is 1761, after removal 1535. If my maths is correct that is 226 of empty lines just sitting there doing nothing but taking up server time.
I think you can resolve this yourself by using a minification plugin.
If you’re asking because you’re curious – whitespace is used to help developers read code. That is why it’s there in the original files. If you’re serving a file to a browser (and not a developer) then the minification should happen on a copy of the file. Not the source files.
Hi Andrew
I think you are missing the point. If all coders did it across the web it would make a large difference.
I know there are plugins available but why have another plugin to do what good practice should be doing anyway.
If you are concerned about adjusting code (developers) this could be easily solved by providing a link to a developers version. The production version should have whitespace removed.
Doing it on my own site makes a difference.
I don’t think you’re in a position to tell people how to code.
That I consider to be a rather rude reply Andrew.
The solution is there. If you want to tell people how to code then you’re not going to get far.
*Drinks coffee. Coffee is good.*
I consider WP to be great but I do not understand why coders do not remove whitespace from their code before publishing.
A couple of reasons I think and the only cases that count are CSS and javascript. WordPress core files already do that.
If you look you will find minimize versions of files in the source code. Just look in
/wp-admin/js/
or/wp-includes/
and you will find (does a little check) 217 minified js files. For CSS you will find…120 files.These files have names ending with
.min.js
and.min.css
and are easy to find. There is zero advantage to minifying PHP files. None, zip, nada. ??The reason is that PHP is interpreted and the output (the executed code) is the same with or without eliminating the white spaces. Removing the white space there would not help anything but would make the PHP code unreadable to regular people and that’s really against the whole idea of opensource software.
We want the PHP files to be readable. It encourages people suggest modifications and keeps code participation open to everyone.
As to those other CSS files (or even js files) you can always suggest a patch to get those minified as well. ??
https://make.www.ads-software.com/core/handbook/working-with-trac/submitting-a-patch/
If you look you will find minimize versions of files in the source code. Just look in /wp-admin/js/ or /wp-includes/ and you will find (does a little check) 217 minified js files. For CSS you will find…120 files.
Must admit, I had no idea that these minimised files were included in WP core files. What a good idea but how many know about it?
I take it that we can simply replace the full version with these minimised ones, if we wish too.
There is zero advantage to minifying PHP files.
I have removed unused lines in PHP files and my site is running smoother by doing this. Pages are loading a bit quicker but this maybe because I am looking at all the files and going through the process of removing empty lines of code in all my files.
There has been much talk lately about Google’s new search criteria (since April) and that a number of sites have lost their search position. This is largely to do with sites being mobile friendly, but as those of us know, that take our sites seriously, this is also to do with the size and speed of loading pages for mobiles. I can get 25mb speed using a well known cable network at home but when i come to view my site using a mobile phone it takes ages.
I think WP is a great platform and use it lots, but there is no doubt in my mind, that when I set up a static html site it loads much, much quicker than any CMS (including WP, Joomla, Dupal and others) I have come across, every time.
That is why I am suggesting that the WP community looks into adopting any measure that can improve the size and speed as search engines like Google are demanding smaller sites that fit in with mobile communications.
Please do not misunderstand me, WP is a great platform and many people give their time and effort in making it what it is, but the web is always changing and WP cannot afford to stand still.
Thank you to all those that contribute to WP.
From your recent post, I can say I interpreted you wrong. I’m sorry.
No problem Andrew and thanks.
I have learned something that I never knew before, that WP offers minimised files in the core system. If we all work together we can continue to make WP great going into the future and help each other.
That is what WP is all about, and that is why so many use it.
That is why I am suggesting that the WP community looks into adopting any measure that can improve the size and speed as search engines like Google are demanding smaller sites that fit in with mobile communications.
The size of WP doesn’t come into play very much in regards to site size. That’s almost all theme responsibility. Also, like mentioned, PHP is processed on the server and Google has no idea there are comment blocks and whitespace because the output of the PHP is HTML.
You will do far more to decrease size by using clean code and adopting a mobile-first CSS flow so desktop assets are not ever loaded on mobile devices.
There is zero advantage to minifying PHP files.
I have removed unused lines in PHP files and my site is running smoother by doing this. Pages are loading a bit quicker but this maybe because I am looking at all the files and going through the process of removing empty lines of code in all my files.
I’d just like to chime in and clarify that the first statement is correct. You will get no performance boost from minifying PHP files.
The reason you minify (and concatenate) CSS and JavaScript files is twofold. These files are downloaded to the browser. Each character in the file is a byte.
By minifying them you eliminate unnecessary bytes and reduce the file size. This allows the browser to download the resource faster and thus render the page quicker.
By concatenating, you’re combining all of your javascript or css files into a single file. This eliminates multiple file requests from the browser. The fewer files that have to get requested to display a page, the quicker it will load.
PHP on the other hand is all compiled and run on the server before the output is sent to the browser. If you want to speed up PHP, using an opcode cache to cache the compiled php code will speed up things. Eliminating whitespace in those files won’t. It just makes them harder to read and edit.
Hope this helps clarify a few misconceptions here.
- The topic ‘Removing Whitespace in coding’ is closed to new replies.