Forum Moderators: phranque

Message Too Old, No Replies

Is Google Undermining Best Coding Practices?

By asking us to minify?

         

buckworks

4:02 pm on Oct 25, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



This is a slightly fictionalized version of a conversation I had yesterday.

I was chatting with a friend who told me a bit about a project she was working on. The topic came up of making life easier for future programmers, and commenting and indenting the code was mentioned as part of that.

"But Google doesn't like indented code," I said. "You lose points on your PageSpeed Insights score if you haven't minified your HTML, your CSS, and everything possible." [developers.google.com...]

She took exception to that. "Indenting is best practice. Indenting has been considered best practice since the earliest days of coding. PageSpeed isn’t a programming validator. I don't care what it asks for. I follow Best Practices. My client wants easily maintainable code."

I wondered, "Is indenting all code still best practice in a day when users respond measurably better to faster pages, extra bandwidth will increase costs for many users, not to mention the client, and the biggest search engine has stated a preference for code with no bloat?"

----------

What do folks around here think? Leaving pretty code for the next programmer is A Good Thing, but it is always the highest value? Or should something else take precedence?

Is Google undermining best coding practices by asking us to minify our HTML, CSS etc.?

What is ultimately in the best interest of the client?

not2easy

6:19 pm on Oct 25, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



HTML pages work the same whether in a pretty format or all in one glop that makes it hard to edit, so rather than choose, I do both - same with .css and .js files.

I create a copy of both formats, only the 'minified' version gets uploaded. If I need to work on the code I pull out the working version, when changes are complete I minify a version for upload. The full, easier to work with version occupies the copy in my 'domain folder' to work from. The domain folder has a folder called 'minified versions where new copies are stored for upload. Old versions are archived with a date of changes appended.

I am fortunate enough to use a text editor that lets me "unminify" things if I want to. My view is that Google isn't telling us how to work, they are promoting what works best for accommodating the lowest common denominator of bandwidth.

lucy24

7:37 pm on Oct 25, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I create a copy of both formats, only the 'minified' version gets uploaded.

Exactly. There's your working copy, and your uploaded copy. You might similarly upload the HTML output of a php page whose "dynamic" content hardly ever changes.

But really-- just how many bytes does a minified file save? Compare it to the size of even a single small image ... or, more to the point, the inherent overhead in each separate request. Do search engines have one rule for hand-rolled sites and a different one for any recognizable CMS? Every now and then I amuse myself by opening some random page's html and counting css files listed in the <head>. For a long time the record was 18-- that is, 18 named files. I didn't check whether every last one of those 18 was actually used on the calling page. Last time I snooped, the page I was looking at had over thirty separate CSS files. IANMTU. 33, 34-- I forget the exact number. In the <head>, where they have to be loaded before anything can display -- another issue the page-speed folks keep going on about.

And they want us to minify? The size of a script or style file may be the least of a page's problems.

blend27

8:23 pm on Feb 14, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Indenting is best practice. It does not mean that the final version that is served to a browser(IE, FF) has to be swallowed, all your gigligok comments that you have left.

Comments in the code are most important, specially 2 weeks later.

Formatted source code could have tons of comments but the best practice is to comment them out using serverside technology. Strip White space and CTRLFs, GZIP it and send to the browser.

I just finished a 2 year contract with one of the largest Insurance companies in a, perhaps, world.

One Consultant developer was serving HTML TABLES in reports with 1500 records per. 12 columns. 5-6 MB of white space on each run. When confronted, he replied it does not matter, we are on the Intranet. Took me 15 minutes to cut it down to 120KB.

Another Employee(for the past 10 years) was using inline styles on every TD on similar reports: 1500 rows, 10 columns, each column had inline CSS worth of 150 characters. Can you imagine?

Strip White space and CTRLFs, GZIP it and send to the browser.

DONE, lightning fast!

not2easy

11:01 pm on Feb 14, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I have to quote lucy24 here, though I see this is not exactly a new discussion, it fits:
When Page Speed Insights says to minify your html, css and js, they don't mean minify. I could never understand why they claimed my html was minified (it isn't) while the css and js weren't (and never will be). It's because when they say "minify" they mean "compress" as with gzip.

In Apache the line is
AddOutputFilterByType DEFLATE text/css text/javascript


I have to assume my host already does this with html, so I didn't say anything about it. I just added this line. And abracadabra, now my styles and scripts are "minified" according to Google.

quoted from Msg#: 4736491 here: [webmasterworld.com...] in today's section of the "Google Emailing Non-Mobile Friendly Sites" thread.

Google does confuse people as to best practices, some of it makes one wonder about self serving decisions.. I was looking up their developers' recommendations, carrying them over to 'caniuse' and two of the two recommendations only functioned on Chrome. (The tags were
<picture>
and
srcset
). Though they could work on FF if a person were to edit the configuration file.

Hoople

12:13 am on Feb 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have gotten to be a comment-a-holic. Everything I do is bracketed in comments and separated from the previous block by two new lines.

Indent? You betcha! In the few times i utilize a table it gets the old school triple indent with the on it's own line if defined.

I learned HTML after learning C/ASM, so comments just came naturally <G>

Most of the code reduction I have done (to keep inside a oft quoted 23kb) is to remove the plethora of code bloat from Front Page, esp the pages using the MS proprietary XML markup. Had some pages drop over 65% in size!

lucy24

12:36 am on Feb 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Another Employee(for the past 10 years) was using inline styles on every TD on similar reports: 1500 rows, 10 columns, each column had inline CSS worth of 150 characters. Can you imagine?

I don't need to imagine: I've seen it. When I made ebooks, one of the html-generating tools (which I didn't use) behaved much like a wysiwyg editor, meaning that if you changed something about a table's layout, a new "style: blahblah" was added to every. single. cell. Shudder.

And then there was this hilarious thread [webmasterworld.com] from a few years ago.

Idle query: Why did this come up almost instantly when I searched, while truly important searches for earth-changingly significant discussions lead to nothing but dead ends?