11
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 9:13

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Quote:
Quote:
Exactly would require that the compiled code is compressed before the file is saved in cache...

I saw in this article that:

Quote:
PrestaShop takes the hard work out of combining, compressing and caching CSS and JavaScript by doing it all for you. It has the option to combine all external CSS files into a single CSS file and all external JavaScript files into a single JavaScript file. There is an option to compress inline JavaScript in HTML too. PrestaShop uses Douglas Crockford's JSMin Javascript minified ported to PHP by Ryan Grove for its compression and Smarty to cache the combined, compressed file.

If somebody could implement it in XOOPS, it would be very cool

There is also this article with optimization tips.


For compress Smarty With the Plugin Saci. (Smarty Asset Compiler (sacy))
They explain how: here

I'll try to do an installation on SMARTY neutral. (No Xoops)



12
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 9:18

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Quote:
an follow that...but

is this the file scipt that one needs to download called Smarty-3.1.8. In this package there are 2 folders, one called libs and the other called demo
in the libs and in the libs folder there are more, plugings and sysplugins where the file outputfilter.trimwhitespace.php resides

do one needs to install this Smarty folder in the root system

Advise please


it's here ---> ../Smarty-3.1.8/libs/plugins/outputfilter.trimwhitespace.php

if it does not work is that it is the other smarty folder. (Other version).

You just have to copy paste codes.
Nothing more.

13
rgauci
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 10:03

  • rgauci

  • Not too shy to talk

  • Posts: 173

  • Since: 2007/8/31


I followed what you said and the end result is a blank white page. I am using xoops 2.4.5
Be Set FREE!

14
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 13:48

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Upgrade Xoops.

15
rgauci
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 14:27

  • rgauci

  • Not too shy to talk

  • Posts: 173

  • Since: 2007/8/31


There was no need to upgrade xoops

I just changed this


$xoopsTpl =& $xoTheme->template;
$xoopsTpl->load_filter('output', 'trimwhitespace');

to this

$xoopsTpl =& $xoTheme->template;
$xoopsTpl->load_filter('outputfilter.trimwhitespace);

note the 'outputfilter.trimwhitespace'

and worked fine and fast I must say

thanks for all your work iLuc
Be Set FREE!

16
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/3/13 14:34

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Great ! :)

It's good to know this trick.

$xoopsTpl =& $xoTheme->template;
$xoopsTpl->load_filter('outputfilter.trimwhitespace');

17
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/11/3 18:40

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Hi !!..

Another tip to improve. :)

You disable the solution above.
(Only for those who have set up)
$xoopsTpl->load_filter('outputfilter.trimwhitespace');


The trick that I propose is more interesting. ;)
And easy to implement.

It allows compressed code directly in the files in place.
Therefore, the compression is done "before" saving the file cached.

The previous solution was performing compression (Minify Html) when displaying pages.

The solution that I propose to you now, it will compress the code, when creating the file it is cached.
/xoops_data/caches/smarty_cache/your-file-cache.html.php
/xoops_data/caches/smarty_compile/your-file-cache.html.php

How?
it is very simple.

in folder : /class/smarty/

Open file : Smarty_Compiler.class.php

Add in line 424

Just before this code:

$compiled_content $template_header $compiled_content;
        return 
true;
    }


Add this code:

/*************** HACK iLUC Minify HTML / COMPRESS CODE *******************/
        
$compiled_content trim(preg_replace('/((?)n)[s]+/m''1'$compiled_content));
        
$compiled_content preg_replace('##s'''$compiled_content);
           
$compiled_content preg_replace("/(rn|n|r)/"""$compiled_content);
           
$compiled_content str_replace(CHR(13).CHR(10),"",$compiled_content);
           
$compiled_content preg_replace("/(nn|nnn)/"""$compiled_content);
           
$compiled_content preg_replace("#>(s+)<#s""><"$compiled_content);


At the end, you must have the following:

[...]
if ($this->_init_smarty_vars) {
            $template_header .= "require_once(SMARTY_CORE_DIR 'core.assign_smarty_interface.php');nsmarty_core_assign_smarty_interface(null$this); ?>n";
            $this->_init_smarty_vars = false;
        }

/*************** HACK iLUC Minify HTML / COMPRESS CODE *******************/
        $compiled_content = trim(preg_replace('/((?)n)[s]+/m', '1', $compiled_content));
        $compiled_content = preg_replace('##s', '', $compiled_content);
           $compiled_content = preg_replace("/(rn|n|r)/", "", $compiled_content);
           $compiled_content = str_replace(CHR(13).CHR(10),"",$compiled_content);
           $compiled_content = preg_replace("/(nn|nnn)/", "", $compiled_content);
           $compiled_content = preg_replace("#>(s+)<#s", "><", $compiled_content);

        $compiled_content = $template_header . $compiled_content;
        return true;
    }

[...]



Your compress code is Active !! and even better!


18
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/11/3 18:55

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


To verify that it works.
Open a file cache.

The code should be like this:
- No white space
- No newline

/* Smarty version 2.6.26, created on 2012-11-03 19:50:48
         compiled from /homez.9/disquesvb/www/modules/system/themes/default/xotpl/xo_footer.html */ 
?>
require_once(SMARTY_CORE_DIR 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier''date_format''//www/modules/system/themes/default/xotpl/xo_footer.html'2false),)), $this); ?>
Powered by echo $this->_tpl_vars['xoops_version']; ?> © 2001-echo ((is_array($_tmp=time())) ? $this->_run_mod_handler('date_format'true$_tmp"%Y") : smarty_modifier_date_format($_tmp"%Y")); ?>
echo 'http://www.disques-vinyles.fr/backend.php'?>" title="echo @_OXYGEN_RSS?>">echo 'http://www.disques-vinyles.fr/modules/system/themes/default/img/feed.png'?>" />
->_smarty_include(array('smarty_include_tpl_file' => ($this->_tpl_vars['theme_tpl'])."/xo_uptop.html"'smarty_include_vars' => array()));?>

19
Yurdal
Re: Trick [SMARTY] Compress your code HTML
  • 2012/11/5 16:56

  • Yurdal

  • Friend of XOOPS

  • Posts: 386

  • Since: 2005/3/27


Thanks for the tip, but i see lot of code changes and im now confused

Is it possible to upload the modified files header.php and outputfilter.trimwhitespace.php so that anyone who want to use this hack only have to upload it to there website ?

20
iLuc
Re: Trick [SMARTY] Compress your code HTML
  • 2012/11/6 9:58

  • iLuc

  • Just popping in

  • Posts: 47

  • Since: 2009/6/6 0


Hi Yurdal,

I use this trick on this site.
http://www.disques-vinyles.fr

And also on another site that uses Smarty.
http://www.annuaire.avisduweb.fr ( No Xoops, this is a Web Directory )

But the change is the same, the same file:
Smarty_Compiler.class.php

I disabled for that one line of code, due to an Ajax script.
So the code is left aligned. That is fine too.

I advise you to use the second tip, not the one with:
outputfilter.trimwhitespace.php

The two can work together, but it is useless, the display will prompt more work. The second solution I propose is more effective.

You use any version of Xoops?

Luc


Login

Who's Online

177 user(s) are online (134 user(s) are browsing Support Forums)


Members: 0


Guests: 177


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits