Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ajax SEO snippet in 140 bytes
var nav=$('a');
$.address.crawlable(1).state('/ajax-seo').init(function(){
nav.address();
}).change(function(e){
var content=$('#content'),
timer=window.setTimeout(function(){
content.html('Loading seems to be taking a while.');
},3800),clearTimeout=window.clearTimeout(timer);
$.ajax({
type:'GET',
url:'api'+(e.path.length!=1 ? '/'+encodeURIComponent(e.path.toLowerCase().substr(1)) : ''),
dataType:'json',
cache:true,
beforeSend:function(){
document.title='Loading...';
content.fadeTo(200,0.33);
},
success:function(data,textStatus,jqXHR){
clearTimeout;
nav.each(function(){
if($(this).attr('href')==(($.address.state()+decodeURI(e.path)).replace(/\/\//,'/'))){
$(this).addClass('selected').focus();
}else{
$(this).removeAttr('class');
}
});
document.title=data.title+' - Ajax SEO';
content.fadeTo(20,1).removeAttr('style').html(data.content);
if($.browser.msie){content.removeAttr('filter');}
},
error:function(jqXHR,textStatus,errorThrown){
clearTimeout;
nav.each(function(){
$(this).removeAttr('class');
});
document.title='404 Page not found';
content.fadeTo(20,1).removeAttr('style').html('<h1>404 Page not found</h1>\r<p>Sorry, this page cannot be found.</p>\r');
if($.browser.msie){content.removeAttr('filter');}
}
});
});
GPL and MIT LICENSE
{
"name": "Ajax SEO",
"description": "Ajax SEO maximized performance - speed, accessibility, user-friendly",
"keywords": [
"ajax",
"seo",
"jquery",
"json"
]
}
<!DOCTYPE html>
<title>Ajax SEO</title>
<a class=selected href="/ajax-seo/">Home</a>
<a href="/ajax-seo/about">About</a>
<a href="/ajax-seo/contact" title="Contact us">Contact</a>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js></script>
<script src=https://raw.github.com/laukstein/ajax-seo/master/images/jquery.address.js></script>
<span id=content></span>
@tsaniel

This comment has been minimized.

Copy link

commented Nov 29, 2011

I wonder how will it be fitted into 140bytes.

@laukstein

This comment has been minimized.

Copy link
Owner Author

commented Nov 29, 2011

I just though maybe it might have some improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.