Ajax SEO snippet (jQuery), https://github.com/laukstein/ajax-seo
-
-
Save laukstein/1403670 to your computer and use it in GitHub Desktop.
Ajax SEO snippet in 140 bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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');} | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GPL and MIT LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Ajax SEO", | |
"description": "Ajax SEO maximized performance - speed, accessibility, user-friendly", | |
"keywords": [ | |
"ajax", | |
"seo", | |
"jquery", | |
"json" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
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
I wonder how will it be fitted into 140bytes.