The document discusses various techniques for improving web applications, including:
1. Enabling in-place AJAX reloading of pages using jQuery.
2. Optimizing page loads by only rendering necessary content for AJAX requests.
3. Adding hash URLs to enable back-button functionality when using AJAX.
4. Improving cross-browser compatibility by detecting browsers and conditional loading of styles.
31. <head>
<script src="/js/script.js"></script>
<link rel="stylesheet" href="/css/style.css" />
</head>
<body>
<div id="top">Your site name and nav here</div>
<%= yield %>
</body>
32. <% unless request.xhr? %>
<head>
<script src="/js/script.js"></script>
<link rel="stylesheet" href="/css/style.css" />
</head>
<% end %>
<body>
<% unless request.xhr? %>
<div id="top">Your site name and nav here</div>
<% end %>
<%= yield %>
</body>
33. <% unless request.xhr? %>
<head>
<script src="/js/script.js"></script>
<link rel="stylesheet" href="/css/style.css" />
</head>
<% end %>
<body>
<% unless request.xhr? %>
<div id="top">Your site name and nav here</div>
<% end %>
<%= yield %>
“Hey, don't render this cruft when the
</body> page is loaded via AJAX.”
42. $('a').live('click', function () {
var href = $(this).attr('href');
window.location.hash = '#!' + href;
return false;
});
$.hashListen('!(.*)', function (href) {
43. $('a').live('click', function () {
var href = $(this).attr('href');
window.location.hash = '#!' + href;
return false;
});
$.hashListen('!(.*)', function (href) {
Every time the hash changes to this, do this.
44. $('a').live('click', function () {
var href = $(this).attr('href');
window.location.hash = '#!' + href;
return false;
});
$.hashListen('!(.*)', function (href) {
var href = $(this).attr('href');
$('#loading').show();
$.get(href, function (html) {
var $new = $('<div>').html(html);
$('#content').html($new.find('#content'));
$('#sidebar').html($new.find('#sidebar'));
$('#loading').hide();
});
});
60. class UserAgent
def initialize(ua_string)
@ua = ua_string
end
def webkit?() product?('AppleWebKit'); end
def chrome?() product?('Chrome'); end
def ie6?() detail?(/^MSIE 6/, 'Mozilla'); end
# ...
def product?(spec); !! @ua.match(spec); end
# ...
End
62. class UserAgent
# ...
def body_class
(%w(webkit chrome ios gecko opera ie linux) +
%w(ipad windows mac ie6 ie7 ie8 ie9)).map do |aspect|
aspect if self.send :"#{aspect}?"
end.compact.join(' ')
end
end