ericmckean / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Easier API for page minification #129

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've studies the Minify builder a little, but couldn't make much of the way 
the html is minified.

A nice way would be the following, where Minify would follow the config.
<?php ob_start(); ?>
<!-- html -->

<?
$contents = 0b_get_contents();
ob_end_clean();
require '/min/Minify.php';
Minify::serve('Page', $contents);
// This as a cleaner alternative to 
http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php

Original issue reported on code.google.com by Kramieb@gmail.com on 4 Aug 2009 at 12:58

GoogleCodeExporter commented 9 years ago
Notice this is an enhancement, couldn't figure out how to change it.

Original comment by Kramieb@gmail.com on 4 Aug 2009 at 1:00

GoogleCodeExporter commented 9 years ago
Just a note:

$contents = 0b_get_contents();
ob_end_clean();

is the same as 

$contents = ob_get_clean();

Original comment by Jan.Hend...@googlemail.com on 4 Aug 2009 at 4:29

GoogleCodeExporter commented 9 years ago
Even better:
<?php ob_start(); ?>
<!-- html -->

<?
require '/min/Minify.php';
Minify::serve('Page', $ob_end_clean(););

Original comment by Kramieb@gmail.com on 4 Aug 2009 at 4:34

GoogleCodeExporter commented 9 years ago
How about:

<?php require $_SERVER['DOCUMENT_ROOT'] . '/min/page.php'; ?>
<!-- html -->

page.php could include all needed Minify files and ob_start('ob_minify_page'). 
ob_minify_page() would receive the buffer, check get_included_files() for 
mtimes, 
and return Minify::serve().

This is how http://www.mnot.net/cgi_buffer/ works. It won't work for everyone, 
but I 
like it.

Original comment by mrclay....@gmail.com on 4 Aug 2009 at 4:56

GoogleCodeExporter commented 9 years ago
Does that mean it will be cgi_buffer but better?

Or will this result in an overal compression suite, where you can do something 
like:
http://pastebin.com/f5b41485

Even tought of an complete api, will denote it here when I have it ready.

Original comment by Kramieb@gmail.com on 4 Aug 2009 at 6:13

GoogleCodeExporter commented 9 years ago
It would do everything Minify does for JS/CSS files, but for HTML. So, full 
minification of markup and script/style contents, gzip, cache headers, and 
conditional GET.

I don't want to rewrite href/src to use Minify or automatically inline content. 
Those decisions should stay with the page author.

The only initial limitation is that it wouldn't notice the modification of 
files 
pulled in using readfile(), since those don't show up in get_included_files(), 
but 
most people don't use readfile for templating anyway.

Original comment by mrclay....@gmail.com on 4 Aug 2009 at 6:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
For the case you may want to make it a more generic suit:
http://pastebin.com/f44e13ac2

Oh, and forgot to say it, it won't replace the current functionality, but 
should be 
nice.

Original comment by Kramieb@gmail.com on 4 Aug 2009 at 6:40

GoogleCodeExporter commented 9 years ago
R350 has this working. Just copy the two files in /min/, and at the top of your 
file:
require $_SERVER['DOCUMENT_ROOT'] . '/min/pageBuffer.php';

A different API could prevent the page code from being executed at all when the 
cache was fresh (You'd set a server-side maxAge). This would only require that 
another file be appended:

require $_SERVER['DOCUMENT_ROOT'] . '/min/pageCache_pre.php'; 
/* PHP Page here. Not executed if Minify's cache fresh. */
require $_SERVER['DOCUMENT_ROOT'] . '/min/pageCache_post.php';

Original comment by mrclay....@gmail.com on 5 Aug 2009 at 7:53

GoogleCodeExporter commented 9 years ago
Noticed a issue, it generates line endings on every first space after the tag 
title.
Example:

<div id="header"></div>
Becomes:
<div
id="header"></div>
And:
<img src="foo.jpg" />
Becomes:
<img
src="foo.jpg" />

Original comment by Kramieb@gmail.com on 14 Sep 2009 at 5:59

GoogleCodeExporter commented 9 years ago
This is done to limit line lengths (which I've been told can cause problems in 
some 
apps) and doesn't add any weight ("\n" = 1 byte).

Original comment by mrclay....@gmail.com on 14 Sep 2009 at 9:03

GoogleCodeExporter commented 9 years ago
This doesn't work anymore with the recent minify (files changed), how to get 
this behavior back?

Original comment by Kramieb@gmail.com on 3 Apr 2010 at 1:19

GoogleCodeExporter commented 9 years ago
Are you using /min/pageBuffer.php? Do you get an error? Checked PHP's error log?

Original comment by mrclay....@gmail.com on 3 Apr 2010 at 3:07

GoogleCodeExporter commented 9 years ago
It simply wasn't in the latest download. But I just realized it is in the 
online repo. 
Gonna try that first.

Original comment by Kramieb@gmail.com on 3 Apr 2010 at 3:39