Skip to content

Commit

Permalink
extensive page/site performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelkiessling committed Oct 9, 2011
1 parent 206e364 commit fc8a94d
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 28 deletions.
1 change: 1 addition & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AddType x-mapp-php5 .php .shtml .html .htm .txt .js .css .png .jpg .gif
18 changes: 18 additions & 0 deletions footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$output = ob_get_clean(); // Gesamte Ausgabe, die an den Client gesendet werden soll, abfangen und zwischenspeichern

$etag = '"'.sha1($output).'"'; // Prüfsumme der Ausgabe berechnen// Ist der Inhalt identisch mit dem, den der Client gecached hat?
if ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) // Wenn ja, dann sende nur den Status 304
{
header('HTTP/1.x 304 Not Modified');
header('Etag: '.$etag);
die();
}
else // Wenn nicht, dann sende den Inhalt inkl. des neuen Etags
{
header('Etag: '.$etag);
echo $output;
die();
}
30 changes: 30 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

ob_start();

$pathinfo = pathinfo($_ENV['SCRIPT_FILENAME']);
$extension = $pathinfo['extension'];

if ($extension != 'html') {
header('Cache-Control: max-age=604800'); // 1 week
}

if ($extension == 'css') {
header('Content-type: text/css; charset=utf-8');
}

if ($extension == 'js') {
header('Content-type: text/javascript; charset=utf-8');
}

if ($extension == 'png') {
header('Content-type: image/png');
}

if ($extension == 'jpg') {
header('Content-type: image/jpeg');
}

if ($extension == 'gif') {
header('Content-type: image/gif');
}
85 changes: 57 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,36 +371,76 @@
display: none;
}
</style>

<script type="text/javascript" src="mootools-core-1.3.1-full-compat-yc.js"></script>
<script type="text/javascript" src="TOC.js"></script>

<script type="text/javascript">
window.addEvent('domready', function() {
var toc = new TOC('table-of-contents');
// Function to asyncronously load local js files
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
script.async = true;

if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}

script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}

// Table of Contents script
loadScript("mootools-core-1.3.1-full-compat-yc.js", function(){
loadScript("TOC.js", function(){
window.addEvent('domready', function() {
var toc = new TOC('table-of-contents');
});
});
});
</script>
<script type="text/javascript" src="prettify/prettify.js"></script>
<script type="text/javascript">

// Code prettyfier
loadScript("prettify/prettify.js", function(){});

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2127388-6']);
_gaq.push(['_trackPageview']);

(function() {
function loadAnalytics() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
/* <![CDATA[ */
(function() {
}
setTimeout(loadAnalytics, 1);

// Disqus
var disqus_shortname = 'nodebeginner';
var disqus_identifier = 'nodebeginner-book';
var disqus_url = 'http://www.nodebeginner.org/';
function loadDisqus() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://mediacdn.disqus.com/1317948585/build/system/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}
setTimeout(loadDisqus, 1);

// Flattr
function loadFlattr() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
t.parentNode.insertBefore(s, t);
})();
/* ]]> */
}
setTimeout(loadFlattr, 1);
</script>
</head>
<body onload="prettyPrint();">
Expand Down Expand Up @@ -3094,21 +3134,10 @@ <h2>Conclusion and outlook</h2>
</div>

<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'nodebeginner';
var disqus_identifier = 'nodebeginner-book';
var disqus_url = 'http://www.nodebeginner.org/';

(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>

<div id="footer">
<p id="ccimage">
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" width="88" height="31"/></a>
</p>
<p>
<span xmlns:dct="http://purl.org/dc/terms/">The Node Beginner Book</span>
Expand Down
4 changes: 4 additions & 0 deletions php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
short_open_tag=off
output_handler=ob_gzhandler
auto_prepend_file=/kunden/homepages/0/d271931425/htdocs/www.nodebeginner.org/header.php
auto_append_file=/kunden/homepages/0/d271931425/htdocs/www.nodebeginner.org/footer.php
1 change: 1 addition & 0 deletions prettify/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AddType x-mapp-php5 .php .shtml .html .htm .txt .js .css .png .jpg .gif
4 changes: 4 additions & 0 deletions prettify/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
short_open_tag=off
output_handler=ob_gzhandler
auto_prepend_file=/kunden/homepages/0/d271931425/htdocs/www.nodebeginner.org/header.php
auto_append_file=/kunden/homepages/0/d271931425/htdocs/www.nodebeginner.org/footer.php

0 comments on commit fc8a94d

Please sign in to comment.