📜 ⬆️ ⬇️

How I followed the webo.in tips

grinkevich.by Today I studied the tips of the webo.in service. I wanted to tell you what I did and how.


1. CSS files can be reduced in size. JS-files can be reduced in size.

Not much and they are big for me, but if you can, then all right.

1. yuilibrary.com/downloads/#yuicompressor - downloaded
2.> java -jar yuicompressor-2.4.2.jar main-src.js -o main.js
3.> java -jar yuicompressor-2.4.2.jar main-src.css -o main.css
')
Item one is ready.

2. Take out javascript and CSS to external files.

Google counter should be hidden in main.js. Not everything works as you want, I had to read different texts:

1. community.livejournal.com/ru_coding/243574.html
2. stevesouders.com/efws/script-onload.php
3. blog.andrewcantino.com/2008/11/23/replacement-for-script-onload-in-ie - there is more on the topic, but the previous version was enough for me. Did not check, but added to bookmarks.

So, main.js is replenished with such lines:

function loadScript(url, onload)
{ s = document .createElement( 'script' );
s.setAttribute( 'type' , 'text/javascript' );
s.setAttribute( 'src' , url);

s.onload = function () { // FF, Opera
if (!s.onloadDone) // Opera
{
s.onloadDone = true ;
if (onload) onload();
}
};

s.onreadystatechange = function () {
if ( "loaded" === s.readyState && !s.onloadDone ) { // IE, Opera
s.onloadDone = true ;
if (onload) onload();
}
}

document .getElementsByTagName( 'head' )[0].appendChild(s); }

function analytics()
{
loadScript( 'http://www.google-analytics.com/ga.js' ,
function ()
{ try {
var pageTracker = _gat._getTracker( "UA-2367900-6" );

pageTracker._addOrganic( "mail.ru" , "q" );
pageTracker._addOrganic( "rambler" , "query" );
pageTracker._addOrganic( "webalta" , "q" );
pageTracker._addOrganic( "aport" , "r" );
pageTracker._addOrganic( "tut.by" , "query" );
pageTracker._addOrganic( "all.by" , "query" );

pageTracker._initData();
pageTracker._trackPageview();
//alert(pageTracker); // Ok?
} catch (err) {} }
); }

Object.prototype.attachEvent = function (sEvent, fnHandler, bUseCapture) {
this .addEventListener(sEvent.indexOf( 'on' ) == 0 ? sEvent.replace( 'on' , '' ) : sEvent, fnHandler, bUseCapture);
}

window.attachEvent( 'onload' , analytics, true );


* This source code was highlighted with Source Code Highlighter .

I removed a couple of lines from one place and added 10 times more to another, optimizer :) I learned new mini-tricks.

3. HTML files can be reduced in size. Caching is not enabled for static files.

It turned out such a function. Used after ob_get_contents ();

function filterContent($data)
{ $data = preg_replace( '#\s{2,}#' , ' ' , $data);
$data = preg_replace( '#<!--.+?-->#s' , '' , $data);
return $data;
}


* This source code was highlighted with Source Code Highlighter .

In .htaccess:
# server-tuning.info/apache/content-compressing.html
AddOutputFilterByType DEFLATE text/html application/xhtml+xml text/plain text/xml \
text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip- only -text/html
BrowserMatch ^Mozilla/4\.0[678] no -gzip
BrowserMatch \bMSIE ! no -gzip !gzip- only -text/html
Header append Vary User -Agent env=!dont-vary

# studio.tellme.com/vxml2/ovw/perf/cache_apache13.html
<IfModule mod_expires.c>
<FilesMatch "\.css$">
ExpiresActive on
ExpiresDefault "access plus 1 year "
FileETag none
</FilesMatch>
<FilesMatch "\.js$">
ExpiresActive on
ExpiresDefault "access plus 1 year "
FileETag none
</FilesMatch>
</IfModule>


* This source code was highlighted with Source Code Highlighter .


grinkevich.by And that's all, now I have such a pimp. There are questions.

1. Anyone tell you how to deal with the remaining two tips? Something is plagued by doubts about the correctness of adding the entire contents of the styles and js to the page due to two unnecessary requests.

2. Why do I have as much as 166% possible acceleration?

My site is similar to google - the same cool))

UPD: updated the tip clipping for homm.
FileETag none - 10x 2 volinrok

Source: https://habr.com/ru/post/70969/


All Articles