Table of Contents

  1. Preface xxix

  2. Acknowledgments xxxv

  1. Chapter 1 Introduction to Web Development 1

    1. 1.1 A Complicated Ecosystem 2

    2. 1.2 Definitions and History 4

      1. A Short History of the Internet 4

      2. The Birth of the Web 7

      3. Web Applications in Comparison to Desktop Applications 8

      4. From Static to Dynamic (and Back to Static) 10

    3. 1.3 The Client-Server Model 15

      1. The Client 17

      2. The Server 17

      3. Server Types 17

      4. Real-World Server Installations 19

      5. Cloud Servers 23

    4. 1.4 Where Is the Internet? 24

      1. From the Computer to Outside the Home 25

      2. From the Home to the Ocean’s Edge 26

      3. How the Internet Is Organized Today 28

    5. 1.5 Working in Web Development 31

      1. Roles and Skills 32

      2. Types of Web Development Companies 36

    1. 1.6 Chapter Summary 40

    2. Key Terms 40

    3. Review Questions 41

    4. References 41

  2. Chapter 2 How the Web Works 42

    1. 2.1 Internet Protocols 43

      1. A Layered Architecture 43

      2. Link Layer 43

      3. Internet Layer 44

      4. Transport Layer 47

      5. Application Layer 48

    2. 2.2 Domain Name System 49

      1. Name Levels 51

      2. Name Registration 53

      3. Address Resolution 55

    3. 2.3 Uniform Resource Locators 58

      1. Protocol 58

      2. Domain 58

      3. Port 58

      4. Path 59

      5. Query String 59

      6. Fragment 59

    4. 2.4 Hypertext Transfer Protocol 60

      1. Headers 61

      2. Request Methods 62

      3. Response Codes 64

    5. 2.5 Web Browsers 64

      1. Fetching a Web Page 65

      2. Browser Rendering 65

      3. Browser Caching 67

      4. Browser Features 68

      5. Browser Extensions 68

    6. 2.6 Web Servers 69

      1. Operating Systems 69

      2. Web Server Software 70

      3. Database Software 70

      4. Scripting Software 70

    1. 2.7 Chapter Summary 71

    2. Key Terms 71

    3. Review Questions 72

    4. References 72

  3. Chapter 3 HTML 1: Introduction 73

    1. 3.1 What Is HTML and Where Did It Come From? 74

      1. XHTML 76

      2. HTML5 78

    2. 3.2 HTML Syntax 79

      1. Elements and Attributes 79

      2. Nesting HTML Elements 80

    3. 3.3 Semantic Markup 81

    4. 3.4 Structure of HTML Documents 84

      1. DOCTYPE 85

      2. Head and Body 85

    5. 3.5 Quick Tour of HTML Elements 87

      1. Headings 87

      2. Paragraphs and Divisions 91

      3. Links 92

      4. URL Relative Referencing 92

      5. Inline Text Elements 95

      6. Images 95

      7. Character Entities 98

      8. Lists 99

    6. 3.6 HTML5 Semantic Structure Elements 102

      1. Header and Footer 103

      2. Navigation 104

      3. Main 105

      4. Articles and Sections 106

      5. Figure and Figure Captions 106

      6. Aside 108

      7. Details and Summary 109

      8. Additional Semantic Elements 110

    1. 3.7 Chapter Summary 116

    2. Key Terms 116

    3. Review Questions 116

    4. Hands-On Projects 117

  4. Chapter 4 CSS 1: Selectors and Basic Styling 122

    1. 4.1 What Is CSS? 123

      1. Benefits of CSS 123

      2. CSS Versions 123

      3. Browser Adoption 124

    2. 4.2 CSS Syntax 125

      1. Selectors 126

      2. Properties 126

      3. Values 127

    3. 4.3 Location of Styles 130

      1. Inline Styles 130

      2. Embedded Style Sheet 131

      3. External Style Sheet 131

    4. 4.4 Selectors 132

      1. Element Selectors 133

      2. Class Selectors 133

      3. Id Selectors 135

      4. Attribute Selectors 136

      5. Pseudo-Element and Pseudo-Class Selectors 136

      6. Contextual Selectors 139

    5. 4.5 The Cascade: How Styles Interact 142

      1. Inheritance 143

      2. Specificity 145

      3. Location 146

    6. 4.6 The Box Model 149

      1. Block versus Inline Elements 149

      2. Background 153

      3. Borders and Box Shadow 155

      4. Margins and Padding 156

      5. Box Dimensions 159

    7. 4.7 CSS Text Styling 165

      1. Font Family 165

      2. Font Sizes 167

      3. Font Weight 171

      4. Paragraph Properties 172

    8. 4.8 CSS Frameworks and Variables 174

      1. What is a CSS Framework? 175

      2. CSS Variables 181

    1. 4.9 Chapter Summary 183

    2. Key Terms 183

    3. Review Questions 183

    4. Hands-On Practice 184

    5. References 188

  5. Chapter 5 HTML 2: Tables and Forms 189

    1. 5.1 HTML Tables 190

      1. Basic Table Structure 190

      2. Spanning Rows and Columns 191

      3. Additional Table Elements 191

      4. Using Tables for Layout 194

    2. 5.2 Styling Tables 195

      1. Table Borders 195

      2. Boxes and Zebras 197

    3. 5.3 Introducing Forms 199

      1. Form Structure 199

      2. How Forms Work 200

      3. Query Strings 201

      4. The <form> Element 202

    4. 5.4 Form Control Elements 204

      1. Text Input Controls 204

      2. Choice Controls 205

      3. Button Controls 209

      4. Specialized Controls 209

      5. Date and Time Controls 213

    5. 5.5 Table and Form Accessibility 215

      1. Accessible Tables 216

      2. Accessible Forms 217

    6. 5.6 Styling and Designing Forms 218

      1. Styling Form Elements 219

      2. Form Design 220

    7. 5.7 Validating User Input 222

      1. Types of Input Validation 222

      2. Notifying the User 223

      3. How to Reduce Validation Errors 224

      4. Where to Perform Validation 227

    1. 5.8 Chapter Summary 234

    2. Key Terms 234

    3. Review Questions 234

    4. Hands-On Practice 235

  6. Chapter 6 Web Media 240

    1. 6.1 Representing Digital Images 241

      1. Image Types 241

      2. Color Models 242

    2. 6.2 Image Concepts 250

      1. Color Depth 250

      2. Image Size 251

      3. Display Resolution 254

    3. 6.3 File Formats 258

      1. JPEG 258

      2. GIF 259

      3. PNG 264

      4. SVG 264

      5. Other Formats 265

    4. 6.4 Audio and Video 268

      1. Media Concepts 268

      2. Browser Video Support 269

      3. Browser Audio Support 271

    5. 6.5 Working with Color 273

      1. Picking Colors 274

      2. Define Shades 275

    1. 6.6 Chapter Summary 277

    2. Key Terms 277

    3. Review Questions 277

    4. Hands-On Practice 278

  7. Chapter 7 CSS 2: Layout 282

    1. 7.1 Older Approaches to CSS Layout 283

      1. Floating Elements 283

      2. Positioning Elements 284

      3. Overlapping and Hiding Elements 288

    2. 7.2 Flexbox Layout 292

      1. Flex Containers and Flex Items 293

      2. Use Cases for Flexbox 294

    3. 7.3 Grid Layout 298

      1. Specifying the Grid Structure 299

      2. Explicit Grid Placement 300

      3. Cell Properties 302

      4. Nested Grids 302

      5. Grid Areas 306

      6. Grid and Flexbox Together 306

    4. 7.4 Responsive Design 310

      1. Setting Viewports 313

      2. Media Queries 314

      3. Scaling Images 318

    5. 7.5 CSS Effects 321

      1. Transforms 322

      2. Filters 324

      3. Transitions 324

      4. Animations 329

    6. 7.6 CSS Preprocessors 332

      1. The Basics of Sass 333

      2. Mixins and Functions 335

      3. Modules 336

    1. 7.7 Chapter Summary 340

    2. Key Terms 340

    3. Review Questions 340

    4. Hands-On Practice 341

    5. References 347

  8. Chapter 8 JavaScript 1: Language Fundamentals 348

    1. 8.1 What is JavaScript and What Can It Do? 349

      1. Client-Side Scripting 350

      2. JavaScript’s History 352

      3. JavaScript and Web 2.0 353

      4. JavaScript in Contemporary Software Development 354

    2. 8.2 Where Does JavaScript Go? 356

      1. Inline JavaScript 356

      2. Embedded JavaScript 356

      3. External JavaScript 358

      4. Users without JavaScript 359

    3. 8.3 Variables and Data Types 359

      1. JavaScript Output 362

      2. Data Types 364

      3. Built-In Objects 366

      4. Concatenation 368

    4. 8.4 Conditionals 369

      1. Truthy and Falsy 371

    5. 8.5 Loops 372

      1. While and do . . . while Loops 373

      2. For Loops 373

    6. 8.6 Arrays 375

      1. Iterating an array using for . . . of 378

      2. Array Destructuring 378

    7. 8.7 Objects 380

      1. Object Creation Using Object Literal Notation 380

      2. Object Creation Using Object Constructor 381

      3. Object Destructuring 382

      4. JSON 385

    8. 8.8 Functions 388

      1. Function Declarations vs. Function Expressions 388

      2. Nested Functions 391

      3. Hoisting in JavaScript 392

      4. Callback Functions 394

      5. Objects and Functions Together 396

      6. Function Constructors 397

      7. Arrow Syntax 399

    9. 8.9 Scope and Closures in JavaScript 403

      1. Scope in JavaScript 403

      2. Closures in JavaScript 408

    1. 8.10 Chapter Summary 411

    2. Key Terms 412

    3. Review Questions 412

    4. Hands-On Practice 413

    5. References 417

  9. Chapter 9 JavaScript 2: Using JavaScript 418

    1. 9.1 The Document Object Model (DOM) 419

      1. Nodes and NodeLists 420

      2. Document Object 420

      3. Selection Methods 422

      4. Element Node Object 424

    2. 9.2 Modifying the DOM 427

      1. Changing an Element’s Style 427

      2. InnerHTML vs textContent vs DOM Manipulation 429

      3. DOM Manipulation Methods 430

      4. DOM Timing 433

    3. 9.3 Events 436

      1. Implementing an Event Handler 436

      2. Page Loading and the DOM 439

      3. Event Object 440

      4. Event Propagation 440

      5. Event Delegation 444

      6. Using the Dataset Property 446

    4. 9.4 Event Types 448

      1. Mouse Events 448

      2. Keyboard Events 448

      3. Form Events 450

      4. Media Events 451

      5. Frame Events 451

    5. 9.5 Forms in JavaScript 456

      1. Responding to Form Movement Events 458

      2. Responding to Form Changes Events 458

      3. Validating a Submitted Form 458

      4. Submitting Forms 462

    6. 9.6 Regular Expressions 463

      1. Regular Expression Syntax 463

      2. Extended Example 465

    1. 9.7 Chapter Summary 472

    2. Key Terms 472

    3. Review Questions 473

    4. Hands-On Practice 473

    5. References 479

  10. Chapter 10 JavaScript 3: Additional Features 480

    1. 10.1 Array Functions 481

      1. forEach 481

      2. Find, Filter, Map, and Reduce 482

      3. Sort 484

    2. 10.2 Prototypes, Classes, and Modules 485

      1. Using Prototypes 487

      2. Classes 491

      3. Modules 493

    3. 10.3 Asynchronous Coding with JavaScript 499

      1. Fetching Data from a Web API 503

      2. Promises 514

      3. Async and Await 518

    4. 10.4 Using Browser APIs 524

      1. Web Storage API 524

      2. Web Speech API 526

      3. GeoLocation 527

    5. 10.5 Using External APIs 529

      1. Google Maps 529

      2. Charting with Plotly.js 531

    1. 10.6 Chapter Summary 539

    2. Key Terms 539

    3. Review Questions 539

    4. Hands-On Practice 540

    5. References 544

  11. Chapter 11 JavaScript 4: React 545

    1. 11.1 JavaScript Front-End Frameworks 546

      1. Why Do We Need Frameworks? 546

      2. React, Angular, and Vue 547

    2. 11.2 Introducing React 551

      1. React Components 553

    3. 11.3 Props, State, Behavior, and Forms 557

      1. Props 557

      2. State 561

      3. Behaviors 563

      4. Forms in React 568

      5. Component Data Flow 570

    4. 11.4 React Build Approach 577

      1. Build Tools 577

      2. Create React App 579

      3. Other React Build Approaches 582

    5. 11.5 React Lifecycle 582

      1. Fetching Data 583

    6. 11.6 Extending React 584

      1. Routing 584

      2. CSS in React 587

      3. Other Approaches to State 588

    1. 11.7 Chapter Summary 596

    2. Key Terms 597

    3. Review Questions 597

    4. Hands-On Practice 597

    5. References 602

  12. Chapter 12 Server-Side Development 1: PHP 603

    1. 12.1 What is Server-Side Development? 604

      1. Front End versus Back End 604

      2. Common Server-Side Technologies 605

    2. 12.2 PHP Language Fundamentals 611

      1. PHP Tags 611

      2. Variables and Data Types 613

      3. Writing to Output 614

      4. Concatenation 615

    3. 12.3 Program Control 620

      1. if . . . else 620

      2. switch . . . case 621

      3. while and do . . . while 622

      4. for 623

      5. Alternate Syntax for Control Structures 624

      6. Include Files 624

    4. 12.4 Functions 627

      1. Function Syntax 627

      2. Invoking a Function 628

      3. Parameters 629

      4. Variable Scope within Functions 632

    5. 12.5 Arrays 635

      1. Defining and Accessing an Array 635

      2. Multidimensional Arrays 636

      3. Iterating through an Array 639

      4. Adding and Deleting Elements 640

    6. 12.6 Classes and Objects 643

      1. Terminology 643

      2. Defining Classes 644

      3. Instantiating Objects 644

      4. Properties 645

      5. Constructors 645

      6. Method 646

      7. Visibility 648

      8. Static Members 649

      9. Inheritance 651

    7. 12.7 $_GET and $_POST Superglobal Arrays 652

      1. Superglobal Arrays 652

      2. Determining If Any Data Sent 655

      3. Accessing Form Array Data 658

      4. Using Query Strings in Hyperlinks 659

      5. Sanitizing Query Strings 660

    8. 12.8 Working with the HTTP Header 664

      1. Redirecting Using Location Header 664

      2. Setting the Content-Type Header 664

    1. 12.9 Chapter Summary 666

    2. Key Terms 667

    3. Review Questions 667

    4. Hands on Practice 667

    5. Reference 672

  13. Chapter 13 Server-Side Development 2: Node.js 673

    1. 13.1 Introducing Node.js 674

      1. Node Advantages 674

      2. Node Disadvantages 679

    2. 13.2 First Steps with Node 682

      1. Simple Node Application 682

      2. Adding Express 685

      3. Environment Variables 686

    3. 13.3 Creating an API in Node 687

      1. Simple API 687

      2. Adding Routes 689

      3. Separating Functionality into Modules 690

    4. 13.4 Creating a CRUD API 692

      1. Passing Data to an API 694

      2. API Testing Tools 695

    5. 13.5 Working with Web Sockets 696

    6. 13.6 View Engines 700

    7. 13.7 Serverless Approaches 702

      1. What Is Serverless? 702

      2. Benefits of Serverless Computing 704

      3. Serverless Technologies 704

    1. 13.8 Chapter Summary 706

    2. Key Terms 707

    3. Review Questions 707

    4. Hands-On Practice 707

    5. References 710

  14. Chapter 14 Working with Databases 711

    1. 14.1 Databases and Web Development 712

      1. The Role of Databases in Web Development 712

    2. 14.2 Managing Databases 715

      1. Command-Line Interface 716

      2. phpMyAdmin 716

      3. MySQL Workbench 718

      4. SQLite Tools 719

      5. MongoDB Tools 719

    3. 14.3 SQL 720

      1. Database Design 720

      2. SELECT Statement 724

      3. INSERT, UPDATE, and DELETE Statements 727

      4. Transactions 727

      5. Data Definition Statements 731

      6. Database Indexes and Efficiency 732

    4. 14.4 Working with SQL in PHP 733

      1. Connecting to a Database 734

      2. Handling Connection Errors 737

      3. Executing the Query 738

      4. Processing the Query Results 739

      5. Freeing Resources and Closing Connection 743

      6. Working with Parameters 744

      7. Using Transactions 747

      8. Designing Data Access 751

    5. 14.5 NoSQL Databases 754

      1. Why (and Why Not) Choose NoSQL? 756

      2. Types of NoSQL Systems 757

    6. 14.6 Working with MongoDB in Node 761

      1. MongoDB Features 761

      2. MongoDB Data Model 762

      3. Working with the MongoDB Shell 764

      4. Accessing MongoDB Data in Node.js 764

    1. 14.7 Chapter Summary 771

    2. Key Terms 772

    3. Review Questions 772

    4. Hands-On Practice 773

    5. References 777

  15. Chapter 15 Managing State 778

    1. 15.1 The Problem of State in Web Applications 779

    2. 15.2 Passing Information in HTTP 781

      1. Passing Information via the URL 781

      2. Passing Information via HTTP Header 782

    3. 15.3 Cookies 785

      1. How Do Cookies Work? 786

      2. Using Cookies in PHP 787

      3. Using Cookies in Node and Express 789

      4. Persistent Cookie Best Practices 789

    4. 15.4 Session State 792

      1. How Does Session State Work? 793

      2. Session Storage and Configuration 794

      3. Session State in PHP 796

      4. Session State in Node 798

    5. 15.5 Caching 799

      1. Page Output Caching 800

      2. Application Data Caching 800

      3. Redis as Caching Service 803

    1. 15.6 Chapter Summary 808

    2. Key Terms 808

    3. Review Questions 808

    4. Hands-On Practice 808

    5. References 812

  16. Chapter 16 Security 813

    1. 16.1 Security Principles 814

      1. Information Security 814

      2. Risk Assessment and Management 815

      3. Security Policy 818

      4. Business Continuity 818

      5. Secure by Design 821

      6. Social Engineering 823

      7. Authentication Factors 824

    2. 16.2 Approaches to Web Authentication 825

      1. Basic HTTP Authentication 826

      2. Form-Based Authentication 827

      3. HTTP Token Authentication 829

      4. Third-Party Authentication 830

    3. 16.3 Cryptography 834

      1. Substitution Ciphers 835

      2. Public Key Cryptography 838

      3. Digital Signatures 840

    4. 16.4 Hypertext Transfer Protocol Secure (HTTPS) 840

      1. SSL/TLS Handshake 842

      2. Certificates and Authorities 842

      3. Migrating to HTTPS 846

    5. 16.5 Security Best Practices 848

      1. Credential Storage 849

      2. Monitor Your Systems 858

      3. Audit and Attack Thyself 859

    6. 16.6 Common Threat Vectors 860

      1. Brute-Force Attacks 860

      2. SQL Injection 861

      3. Cross-Site Scripting (XSS) 863

      4. Cross-Site Request Forgery (CSRF) 868

      5. Insecure Direct Object Reference 869

      6. Denial of Service 870

      7. Security Misconfiguration 871

    1. 16.7 Chapter Summary 874

    2. Key Terms 875

    3. Review Questions 875

    4. Hands-On Practice 876

    5. References 878

  17. Chapter 17 DevOps and Hosting 880

    1. 17.1 DevOps: Development and Operations 881

      1. Continuous Integration, Delivery, and Deployment 881

      2. Testing 882

      3. Infrastructure as Code 885

      4. Microservice Architecture 886

    2. 17.2 Domain Name Administration 888

      1. Registering a Domain Name 888

      2. Updating the Name Servers 891

      3. DNS Record Types 891

      4. Reverse DNS 894

    3. 17.3 Web Server Hosting Options 895

      1. Shared Hosting 895

      2. Dedicated Hosting 898

      3. Collocated Hosting 898

      4. Cloud Hosting 899

    4. 17.4 Virtualization 899

      1. Server Virtualization 899

      2. Cloud Virtualization 904

    5. 17.5 Linux and Web Server Configuration 905

      1. Configuration 907

      2. Starting and Stopping the Server 907

      3. Connection Management 908

      4. Data Compression 910

      5. Encryption and SSL 911

      6. Managing File Ownership and Permissions 913

    6. 17.6 Request and Response Management 914

      1. Managing Multiple Domains on One Web Server 914

      2. Handling Directory Requests 916

      3. Responding to File Requests 917

      4. URL Redirection 918

      5. Managing Access with .htaccess 922

      6. Server Caching 923

    7. 17.7 Web Monitoring 925

      1. Internal Monitoring 925

      2. External Monitoring 927

    1. 17.8 Chapter Summary 927

    2. Key Terms 927

    3. Review Questions 928

    4. Hands-On Practice 928

    5. References 930

  18. Chapter 18 Tools and Traffic 932

    1. 18.1 The History and Anatomy of Search Engines 933

      1. Search Engine Overview 933

    2. 18.2 Web Crawlers and Scrapers 935

      1. Scrapers 936

    3. 18.3 Indexing and Reverse Indexing 938

    4. 18.4 PageRank and Result Order 939

    5. 18.5 Search Engine Optimization 942

      1. Title 943

      2. Meta Tags 943

      3. URLs 945

      4. Site Design 947

      5. Sitemaps 948

      6. Anchor Text 949

      7. Images 949

      8. Content 950

      9. Black-Hat SEO 950

    6. 18.6 Social Networks 955

      1. How Did We Get Here? 956

    7. 18.7 Social Network Integration 958

      1. Basic Social Media Presence 959

      2. Facebook’s Social Plugins 960

      3. Open Graph 964

      4. Twitter’s Widgets 965

      5. Advanced Social Network Integration 969

    8. 18.8 Content Management Systems 970

      1. Components of a Managed Website 970

      2. Types of CMS 971

    9. 18.9 WordPress Overview 972

      1. Post and Page Management 973

      2. WYSIWYG Editors 975

      3. Template Management 976

      4. Menu Control 977

      5. User Management and Roles 977

      6. User Roles 978

      7. Workflow and Version Control 981

      8. Asset Management 982

      9. Search 983

      10. Upgrades and Updates 983

    10. 18.10 WordPress Technical Overview 984

      1. Installation 984

      2. File Structure 984

      3. WordPress Nomenclature 986

      4. WordPress Template Hierarchy 987

    11. 18.11 Modifying Themes 988

      1. Changing Theme Files 990

    12. 18.12 Web Advertising Fundamentals 991

      1. Web Advertising 101 991

      2. Web Advertising Economy 994

    13. 18.13 Support Tools and Analytics 995

      1. Search Engine Webmaster Tools 995

      2. Analytics 996

      3. Third-Party Analytics 999

      4. Performance Tuning and Rating 999

    1. 18.14 Chapter Summary 1005

    2. Key Terms 1005

    3. Review Questions 1006

    4. Hands-On Practice 1006

    5. References 1009

  1. Index 1011

  2. Credits 1029