Web Programming Web Performance and Optimization 1 — Questions and Answers
Question 1: What does minification do to JavaScript or CSS files?
- Encrypts the file content
- Removes whitespace, comments, and shortens names to reduce file size (Correct answer)
- Compresses files using gzip
- Combines multiple files into one
Correct answer: Removes whitespace, comments, and shortens names to reduce file size
Minification removes unnecessary characters like whitespace, comments, and newlines and may shorten variable names to reduce file size without changing functionality.
Question 2: What is the purpose of browser caching in web performance?
- To store user passwords securely
- To save copies of resources locally so they don't need to be re-downloaded on repeat visits (Correct answer)
- To cache database queries on the server
- To store form data temporarily
Correct answer: To save copies of resources locally so they don't need to be re-downloaded on repeat visits
Browser caching stores copies of web resources like images, CSS, and JS on the user's device so they can be loaded from cache on subsequent visits instead of re-downloading.
Question 3: What is lazy loading in web development?
- Loading all resources at page startup
- Deferring the loading of non-critical resources until they are needed (Correct answer)
- Caching resources for offline use
- Preloading resources before they are requested
Correct answer: Deferring the loading of non-critical resources until they are needed
Lazy loading defers loading of non-critical resources (like off-screen images or secondary JavaScript) until they are actually needed, improving initial page load time.
Question 4: What does CDN stand for and what is its primary purpose?
- Centralized Data Network — stores all website data in one place
- Content Delivery Network — distributes content across servers geographically closer to users (Correct answer)
- Client Data Node — caches data on the client side
- Core DNS Network — manages domain name resolution
Correct answer: Content Delivery Network — distributes content across servers geographically closer to users
A CDN (Content Delivery Network) is a distributed network of servers that delivers web content from locations geographically closer to users, reducing latency.
Question 5: What is the purpose of GZIP compression in web performance?
- To encrypt web traffic
- To compress text-based resources like HTML, CSS, and JS before sending them over the network (Correct answer)
- To compress images into smaller files
- To minify JavaScript code
Correct answer: To compress text-based resources like HTML, CSS, and JS before sending them over the network
GZIP compression reduces the size of text-based resources before transmission, which the browser then decompresses, significantly reducing transfer time and bandwidth.
Question 6: What is the Largest Contentful Paint (LCP) metric used for?
- Measuring total page weight in kilobytes
- Measuring the load time of the largest visible content element, a Core Web Vital (Correct answer)
- Counting the number of DOM elements on a page
- Measuring server response time
Correct answer: Measuring the load time of the largest visible content element, a Core Web Vital
LCP (Largest Contentful Paint) is a Core Web Vital that measures the render time of the largest image or text block visible in the viewport, indicating perceived load speed.
What does minification do to JavaScript or CSS files?