Developing Large Web Applications Producing Code That Can Grow and Thrive 1st Edition Kyle Loudon - The ebook in PDF format is ready for download
Developing Large Web Applications Producing Code That Can Grow and Thrive 1st Edition Kyle Loudon - The ebook in PDF format is ready for download
https://ebookultra.com/download/flask-web-development-developing-web-
applications-with-python-2nd-edition-miguel-grinberg/
https://ebookultra.com/download/developing-responsive-web-
applications-with-ajax-and-jquery-1st-edition-sandeep-kumar-patel/
https://ebookultra.com/download/producing-flash-cs3-video-techniques-
for-video-pros-and-web-designers-john-skidgel/
https://ebookultra.com/download/saltwater-aquarium-models-recipes-for-
creating-beautiful-aquariums-that-thrive-1st-edition-john-h-tullock/
Server Driven Web Apps with htmx Any Language Less Code
Simpler Code 1st Edition R. Mark Volkmann
https://ebookultra.com/download/server-driven-web-apps-with-htmx-any-
language-less-code-simpler-code-1st-edition-r-mark-volkmann/
https://ebookultra.com/download/developing-web-apps-with-haskell-and-
yesod-2nd-edition-michael-snoyman/
https://ebookultra.com/download/c-pocket-reference-1st-edition-loudon/
Developing Large Web Applications Producing Code
That Can Grow and Thrive 1st Edition Kyle Loudon
Digital Instant Download
Author(s): Kyle Loudon
ISBN(s): 9780596803025, 0596803028
Edition: 1
File Details: PDF, 2.46 MB
Year: 2010
Language: english
Developing Large Web Applications
Developing Large Web Applications
Kyle Loudon
foreword by Nate Koechley
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
March 2010: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Developing Large Web Applications, the image of a Newfoundland, and related trade
dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
TM
ISBN: 978-0-596-80302-5
[M]
1267035305
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. The Tenets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Managing Complexity 1
Modular Components 3
Achieving Modularity 3
Benefits of Modularity 4
Ten Tenets for Large Web Applications 4
2. Object Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The Fundamentals of OOP 8
Why Object Orientation? 9
UML Class Diagrams 9
Generalization 10
Association 10
Modeling a Web Page 11
Defining Page Types 11
Defining Module Types 11
Writing the Code 12
Achieving Modularity 14
Object-Oriented PHP 15
Classes and Interfaces 15
Inheritance in PHP 19
Object-Oriented JavaScript 22
Objects 22
Inheritance in JavaScript 25
3. Large-Scale HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Modular HTML 28
v
A Bad Example: Using a Table and Presentation Markup 28
A Better Example: Using CSS 30
The Best Example: Semantically Meaningful HTML 31
Benefits of Good HTML 35
HTML Tags 37
Bad HTML Tags 37
Good HTML Tags 38
IDs, Classes, and Names 40
Conventions for Naming 41
XHTML 41
Benefits of XHTML 41
XHTML Guidelines 42
RDFa 45
RDFa Triples 45
Applying RDFa 46
HTML 5 49
4. Large-Scale CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Modular CSS 52
Including CSS 52
Applying CSS 55
Specificity and Importance 57
Scoping with CSS 58
Standard Module Formats 63
Positioning Techniques 65
CSS Box Model 66
Document Flow 67
Relative Positioning 68
Absolute Positioning 68
Floating 70
Layouts and Containers 71
Example Layouts 72
Example Containers 80
Other Practices 82
Browser Reset CSS 83
Font Normalization 85
5. Large-Scale JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Modular JavaScript 88
Including JavaScript 88
Scoping with JavaScript 90
Working with the DOM 92
Common DOM Methods 92
vi | Table of Contents
Popular DOM Libraries 93
Working with Events 98
Event Handling Normalization 99
A Bad Example: Global Data in Event Handlers 99
A Good Example: Object Data in Event Handlers 100
Event-Driven Applications 101
Working with Animation 102
Motion Animation 102
Sizing Animation 103
Color Transition 104
An Example: Chained Selection Lists 105
9. Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Caching Opportunities 222
Caching CSS and JavaScript 222
Caching Modules 227
Caching for Pages 231
Caching with Ajax 231
Using Expires Headers 233
Managing JavaScript 234
JavaScript Placement 234
JavaScript Minification 234
Removing Duplicates 235
Distribution of Assets 237
Content Delivery Networks 237
Minimizing DNS Lookups 237
Minimizing HTTP Requests 238
Control Over Site Metrics 241
Modular Testing 243
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Table of Contents | ix
Foreword
As a little kid, I wondered if I would be big and strong when I grew up. There were a
lot of aspects to growing well. Would I be healthy? Useful? Productive? Successful?
Websites start out small, too. But these humble sites share my childhood dreams. They
want to help more people in more ways; they want to be durable and reliable; they want
to be indispensable and to live forever. In short: they want to be large and successful.
But growing up is hard to do. Challenges accumulate and complexity snowballs.
Expansion means complexity and complexity decay.
—C. Northcote Parkinson
I’ve seen it. The inevitable challenges of growth in websites—data management,
performance—become crippling if mishandled. Things you thought were straightfor-
ward, like HTML, start giving you headaches. From front to back, JavaScript to PHP,
harmony is displaced by dissonance.
Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.
—Alan Perlis
I’ve worked hand-in-hand with Kyle on some of the Web’s largest applications. I’ve
watched him craft CSS systems to make sprawling sites skinable and design Ajax ar-
chitectures that adapt to and enhance the sites. He emerges from the trenches on top
every time. He’s a perpetual teacher, and, like the best in any discipline, also a perpetual
student. We all benefit from his expertise.
Kyle shares his genius and hard-won expertise in this valuable book that will prepare
you and your application for scale and success. The book is well structured and read-
able, with memorable tenets supported by savvy insights, sound philosophy, and fully
functioning code examples. Complexity is inevitable, but success rewards the prepared.
The way to build a complex system that works is to build it from very simple systems
that work.
—Kevin Kelly
xi
During this book’s deft tour of the complete web application stack, Kyle, the perfect
guide, converts lines of explanatory code from one context into insightful tips in
another. Build big by thinking small. Build new by thinking old. Manage scope. Boost
signal and reduce noise. Resist breakage...these things are easy to rattle off, but it takes
an author like Kyle, and a book like this, to make them practical and real.
If you’re ready to build a finely crafted large site, this is the book for you. Learn what
it takes, because today’s compromise is tomorrow’s constraint. Start today, because
the world is waiting for your application.
Grow large and prosper.
—Nate Koechley
San Francisco, January 2010
xii | Foreword
Preface
It’s been a while since I first worked on a book with O’Reilly in 1997. That book was
a practical guide to data structures and algorithms, a subject that, for the most part,
had been defined many years before by some of the early giants of computer science
(Dijkstra, Hoare, Knuth, to name a few). By comparison, I’ve been able to witness the
rapid evolution of the subject of this book from the front lines, and I have had the good
fortune to help refine it myself while working as a web developer at one of the largest
web applications in the world, Yahoo!.
Web developers have a fascinating role. We work just as closely with user experience
designers as with engineers, and sometimes we’re the designers, too. In many ways, we
are guardians of the user experience as a web design goes from its mockup to its im-
plementation. But we also have to write exceptionally good code that performs well in
the challenging environment of web browsers. Today, more than ever, engineers rec-
ognize that web development must be carried out with the same rigor as other types of
software development.
This book presents a number of techniques for applying established practices of good
software engineering to web development—that is, development primarily using the
disparate technologies of HTML, CSS, JavaScript, and server-side scripting languages.
Whereas there are many books on how to use languages, how to use libraries, and how
to approach software engineering, this is the first book to codify many of the techniques
it presents. These techniques will make the components of your own web applications
more reusable, maintainable, and reliable.
Audience
The primary audience for this book is software developers and managers interested in
large web applications; however, you’ll find that the techniques in this book are equally
useful for web applications of any size. Although it’s especially important to follow
good development practices in large web applications, smaller web applications benefit
from many of the same techniques, too.
xiii
To get the most out of this book, you should already be very familiar with HTML, CSS,
and JavaScript; this book does not teach these languages, although it covers many
interesting aspects about them. This book uses PHP as the scripting language for server-
side examples. Many readers will have a good understanding of PHP as well, but even
those who don’t should find the examples easy to follow. PHP is known for its flexi-
bility, ubiquity, and ease of use, so it works well. Most examples can be translated to
other server-side scripting languages fairly easily, if you desire.
xiv | Preface
This icon signifies a tip, suggestion, or general note.
Preface | xv
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/9780596803025
You can find additional information about this book, including electronic versions of
the examples at:
http://kyleloudon.com
To comment or ask technical questions about this book, send email to the following
address, mentioning its ISBN number (978-0-596-80302-5):
[email protected]
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
xvi | Preface
Acknowledgments
This book is the result of having worked with outstanding people both at O’Reilly and
in many projects leading up to the book. For this, I offer my heartfelt thanks.
First, I thank my editor at O’Reilly, Andy Oram. Andy and I worked together on my
first book with O’Reilly, and I had hoped for a long time that working on another book
together would not be a matter of if, but when. Having finished this book, I hope that
another book will be a matter of when again. Andy inspires me with his ability to always
find ways to make things better. His insights appear in one form or another on nearly
every page of this book. Andy also kept our project moving along while being patient
and understanding of the struggle that writers doing other jobs constantly face.
I also extend my sincere thanks to the entire production team at O’Reilly, who con-
stantly impress me with their ability to handle the numerous aspects of production so
smoothly. The ease with which it all seems to take place belies the work that it really
requires. I would also like to thank Amy Thomson, my copyeditor, for having worked
under such tight time constraints at the end of the book.
I send my heartfelt thanks to Nate Koechley for writing the foreword. Nate was one of
my earliest colleagues at Yahoo! to turn me on to the truly awesome potential of web
development. Much of what I’ve tried to capture in this book came from ideas that
Nate worked passionately to instill at Yahoo! and across the Web. I couldn’t have asked
for a more fitting person to write the foreword.
I am grateful to have had outstanding technical reviewers for this book as well.
Christoph Dorn, Steve Griffith, and Nate Koechley each provided an impressive level
of detail and thought in their reviews. The book benefited greatly from their comments.
I would also like to acknowledge the influence of my many colleagues at Yahoo! and
other projects before this. I especially thank Bryce Kujala and Vy Phan, who helped
refine many of the ideas in the book by putting them to the test in practice early on.
I’m also grateful to the exceptional user experience designers with whom I’ve had the
honor to work closest: Veronica Gaspari, Cathy Tiritoglu, and Sasha Verhage.
Finally, I thank Shala, my wife, for her encouragement on another book project; my
parents, Marc and Judy, for their support from afar; Shala’s parents, Elias and Maria,
for their frequent assistance at a moment’s notice; and Julian, who has been my late-
night companion—just too young to know it yet.
Preface | xvii
Other documents randomly have
different content
The Project Gutenberg eBook of Julius
LeVallon: An Episode
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
By
Algernon Blackwood
Author of “The Centaur,” “John Silence,” “The Human Chord,” etc.
TO
M. S-K.
(1906)
Contents
PAGE
BOOK I
Schooldays 3
BOOK II
Edinburgh 77
BOOK III
The Châlet in the Jura Mountains 149
BOOK IV
The Attempted Restitution 267
Book I
SCHOOLDAYS
A. E.
Julius LeVallon
CHAPTER I
I
T was one autumn in the late ’nineties that I found myself at
Bâle, awaiting letters. I was returning leisurely from the
Dolomites, where a climbing holiday had combined pleasantly
with an examination of the geologically interesting Monzoni Valley.
When the claims of the latter were exhausted, however, and I turned
my eyes towards the peaks, it happened that bad weather held
permanent possession of the great grey cliffs and towering
pinnacles, and climbing was out of the question altogether. A world
of savage desolation gloomed down upon me through impenetrable
mists; the scouts of winter’s advance had established themselves
upon all possible points of attack; and the whole tossed wilderness
of precipice and scree lay safe, from my assaults at least, behind a
frontier of furious autumn storms.
The wording startled me; but this surprise, not unmingled with
amusement, gave place immediately to emotions of a deeper and
much more complex order, as I drew an armchair to the window and
resigned myself, half pleasurably, half uneasily, to the flood of
memories that rose from the depths and besieged me with their
atmosphere of half-forgotten boyhood and of early youth.
Pleasurably, because my curiosity was aroused abruptly to a point
my dull tutorial existence now rarely, if ever, knew; uneasily, because
these early associations grouped themselves about the somewhat
unearthly figure of a man with whom once I had been closely
intimate, but who had since disappeared behind a veil of mystery to
follow pursuits where danger to body, mind and soul—it seemed to
me—must be his constant attendant.
Nor is it that I recall that first sight with the added judgment of
later years. I insist that this moment of his entrance into my life was
accompanied by an authentic thrill of wonder that announced his
presence to my nerves, or even deeper, to my very soul. My
sympathetic nervous system was instinctively aware of him. He came
upon me with a kind of rush for which the proper word is startling;
there was nothing gradual about it; its nature was electrifying; and
in some sense he certainly captivated me, for, immediately upon
knowing him, this opening wonder merged in a deep affection of a
kind so intimate, so fearless, so familiar, that it seemed to me that I
must, somewhere, somehow, have known him always. For years to
come it bound me to his side. To the end, moreover, I never quite
lost something of that curious first impression, that he moved,
namely, in an outer world that did not claim him; that those
luminous, inward-peering eyes saw but dimly the objects we call
real; that he saw them as counters in some trivial game he deemed
it not worth while to play; that while, perforce, he used them like the
rest of us, their face-value was as naught compared to what they
symbolised; that, in a word, he stood apart from the vulgar bustle of
ordinary ambitious life, and above it, in a region by himself where he
was forever questing issues of infinitely greater value.
Julius was two forms above me, and for a day or two after my
arrival at mid-term, it appears he was in the sick-room with one of
those strange nervous illnesses that came upon him through life at
intervals, puzzling the doctors and alarming those responsible for his
well-being; accompanied, too, by symptoms that to-day would be
recognised, I imagine, as evidence of a secondary personality. But
on the third or fourth day, just as afternoon “Preparation” was
beginning and we were all shuffling down upon our wooden desks
with a clatter of books and pens, the door beside the great
blackboard opened, and a figure stole into the room, tall, slender,
and unsubstantial as a shadow, yet intensely real.
But from that instant the shadow became most potently real
substance. The boy moved forward to his desk, looked about him as
though to miss no face, and almost immediately across that big
room full of heads and shoulders saw—myself.
Looking back upon this entrance, not from the present long interval
of twenty years, but from a point much nearer to it, and
consequently more sympathetically in touch with my own youth, I
must confess that his presence—his arrival, as it seemed—threw a
momentary clear light of electric sharpness upon certain “inner
scenery” that even at this period of my boyhood was already
beginning to fade away into dimness and “mere imagining.” Which
brings me to a reluctant confession I feel bound to make. I say
“reluctant,” because at the present time I feel intellectually
indisposed to regard that scenery as real. Its origin I know not; its
reality at the time I alone can vouch for. Many children have similar
experiences, I believe; with myself it was exceptionally vivid.
Yet it was upon these glories, and upon this sacred inner scenery,
that the arrival of Julius LeVallon threw a new daylight of stark
intensity. He made them live again. His coming made them awfully
real. They had been fading. Going to school was, it seemed, a
finishing touch of desolating destruction. I felt obliged to give them
up and be a man. Thus ignored, disowned, forgotten of set
deliberation, they sank out of sight and were prepared to disappear,
when suddenly his arrival drew the entire panorama delightfully into
the great light of day again. His presence re-touched, re-coloured
the entire series. He made them true.
“Have you then ... quite ... forgotten ... everything?” he asked,
making dramatic pauses thus between the words.
His eyes, I saw, came up, as it were, from their deep searching.
They rested quietly upon my own, with a reassuring smile that made
them kindly and understanding as those of my own father. He put
his hand on my shoulder in a protective fashion that gave me an
intense desire to remember all the things he wished me to
remember, and thus to prove myself worthy of his interest and
attention. The desire in me was ardent, serious. Its fervency,
moreover, seemed to produce an effect, for immediately there again
rose before my inner vision that flashing scenery I had “imagined” as
a child.
“... in the Other Places,” his voice continued with a droning sound
that was like the sea a long way off, or like wind among the
branches of a tree.
He nodded his head slightly and smiled. I think the “sir,” sounding
so incongruous, caused the smile.
“Yes,” he said in his soft, low voice, “it was with me. Only they
were not dreams. They were real. There’s no good denying what’s
real; it only prevents your remembering properly.”
“And myself?” he went on gently yet eagerly at the same time, his
eyes searching my own. “Don’t you remember—me? Have I, too,
gone quite beyond recall?”
“... carrying the spears up the long stone steps in the sunshine,”
his voice murmured on with a sound like running water, “and the old
man in the robe of yellow standing at the top ... and orchards below,
all white and pink with blossoms dropping in the wind ... and miles
of plain in blue distances far away, the river winding ... and birds
fishing in the shallow places ...”
“... and the burning sunlight on the white walls of the building ...
the cool deep shadows where we talked and slept ... the shouting of
the armies in the distance ... with the glistening of the spears and
shining shields ...”
“... when we lit the signal fires upon the hills,” the voice of
LeVallon broke in softly, looking over his shoulder lest we be
disturbed, “and lay as sentinels all night beside the ashes ... till the
plain showed clearly in the sunrise with the encampments marked
over it like stones ...”
I saw the blue plain fading into distance, and across it a swiftly-
moving cloud of dust that was ominous in character, presaging
attack. Again the scene shifted noiselessly as a picture on a screen,
and a deserted village slid before me, with small houses built of
undressed stone, and roomy paddocks, abandoned to the wild deer
from the hills. I smelt the keen, fresh air and the scent of wild
flowers. A figure, carrying a small blue stick, passed with tearing
rapidity up the empty street.
“... when you were a Runner to the tribe,” the voice stepped
curiously in from a world outside it all, “carrying warnings to the
House of Messengers ... and I held the long night-watches upon the
passes, signalling with the flaming torches to those below ...”
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com