E-Commerce Development E-Commerce Development Performance Optimization 2 — Questions and Answers
Question 1: What is the benefit of using server-side rendering (SSR) or static site generation (SSG) for e-commerce product pages?
- It eliminates the need for a database
- It delivers fully rendered HTML to the browser, improving initial load speed and SEO crawlability (Correct answer)
- It allows the browser to skip JavaScript execution entirely
- It removes the need for HTTPS on product pages
Correct answer: It delivers fully rendered HTML to the browser, improving initial load speed and SEO crawlability
SSR/SSG delivers pre-rendered HTML so the browser can display content immediately and search engine crawlers can index it without executing JavaScript, boosting both performance and SEO.
Question 2: Which HTTP caching header instructs the browser to store a response for a specific duration before revalidating?
- Content-Type
- Cache-Control: max-age (Correct answer)
- X-Frame-Options
- Strict-Transport-Security
Correct answer: Cache-Control: max-age
The `Cache-Control: max-age=<seconds>` header tells browsers and CDNs how long to cache a response before requesting a fresh copy, reducing server load for static assets.
Question 3: What technique reduces the number of HTTP requests by combining multiple CSS or JavaScript files into a single file?
- Minification
- Bundling (concatenation) (Correct answer)
- Tree-shaking
- Prefetching
Correct answer: Bundling (concatenation)
Bundling combines multiple CSS or JS files into a single file, reducing the number of HTTP requests the browser must make, which is especially important for HTTP/1.1 connections.
Question 4: What is 'database connection pooling' and why is it important for high-traffic e-commerce sites?
- Splitting the database across multiple geographic regions
- Reusing a pre-established set of database connections instead of creating a new one per request (Correct answer)
- Caching query results in memory to avoid hitting the database
- Automatically scaling the database server CPU
Correct answer: Reusing a pre-established set of database connections instead of creating a new one per request
Connection pooling maintains a pool of reusable database connections, eliminating the overhead of opening/closing a new connection for every incoming HTTP request during peak traffic.
Question 5: Which caching layer stores frequently accessed query results in memory to reduce repeated database calls on an e-commerce platform?
- Browser localStorage
- Redis or Memcached (Correct answer)
- A CDN edge node
- The web server access log
Correct answer: Redis or Memcached
In-memory caches like Redis or Memcached store query results (e.g., product listings, category menus) in RAM so repeat requests are served in microseconds without hitting the database.
Question 6: What does 'tree-shaking' do in the build process of an e-commerce front-end?
- Removes unused CSS rules from the stylesheet
- Eliminates dead (unreachable) JavaScript code from the final bundle (Correct answer)
- Splits images into smaller tiles for progressive rendering
- Minifies HTML by removing whitespace
Correct answer: Eliminates dead (unreachable) JavaScript code from the final bundle
Tree-shaking statically analyzes module imports and removes any exported functions or variables that are never used, reducing the final JavaScript bundle size.
What is the benefit of using server-side rendering (SSR) or static site generation (SSG) for e-commerce product pages?