M3- Static and dynamic content Flashcards
What is static content?
Static content refers to files that are sent from the server to the browser exactly as they are stored. This includes files like HTML, images, videos, and stylesheets. Static content does not change based on user interactions or other factors.
How is static content delivered?
When you request static content (e.g., clicking on a video), the web server sends the file directly to your browser without any modification.
What is dynamic content?
Dynamic content is generated in real-time based on user input or other conditions. It changes depending on variables like user profiles or current date.
How is dynamic content generated and delivered?
When you request dynamic content (e.g., personalized recommendations), the web server communicates with an application server to generate the content. The application server processes the request, creates the content, and sends it back to the web server, which then delivers it to your browser.
What is the role of a web server?
The web server handles requests from the browser and serves static content directly. For dynamic content, it forwards requests to the application server.
What is the role of an application server?
The application server generates dynamic content by executing application logic, querying databases, and performing complex tasks. It handles the processing required for user-specific data and interactions.
How do web servers and application servers work together?
The web server serves static content directly to the browser. For dynamic content, it forwards the request to the application server, which generates the content. The application server then sends the content back to the web server, which delivers it to the browser.
Why can dynamic content take longer to generate than static content?
Dynamic content requires real-time processing, including running application logic and querying databases, which can be more time-consuming than serving static files.
What is caching and how does it help with dynamic content?
Caching involves storing a copy of dynamically generated content. When the same content is requested again, the web server can quickly serve the cached version instead of regenerating it from scratch. This improves performance by reducing the load on the application server.
How does caching work?
On the first request for dynamic content, the web server asks the application server to generate it. The content is then stored in the cache and sent to the browser. On subsequent requests, the web server serves the cached content, bypassing the application server.
How Caching works (steps and alternatives)?
Step 1: User Makes a Request
- Action: A user interacts with a website or application, requesting dynamic content (e.g., personalized recommendations, user-specific data).
- Example: A user logs into their account to view their dashboard.
Step 2: Web Server Receives the Request
- Action: The web server receives the request and determines that the content is dynamic and not stored as a static file.
- Example: The web server recognizes that it needs to generate personalized content for the user’s dashboard.
Step 3: Check the Cache
- Action: The web server checks if the requested content is already stored in the cache.
- Example: The server looks up the cache to see if it has a recent copy of the user’s dashboard content.
Step 4: Cache Miss (Content Not Found)
- If Cache Miss: The web server does not find the requested content in the cache.
- Action: The server forwards the request to the application server to generate the content.
- Example: The web server sends the request to the application server to generate the dashboard based on the user’s profile.
**Step 5: Application Server Generates Content
**
* Action: The application server processes the request, runs necessary logic, queries the database, and generates the dynamic content.
* Example: The application server creates the personalized dashboard content by retrieving data and applying logic.
Step 6: Store Content in Cache
- Action: The web server receives the generated content from the application server and stores a copy of it in the cache.
- Example: The dashboard content is saved in the cache so it can be quickly accessed for future requests.
Step 7: Send Content to User
- Action: The web server sends the dynamically generated and cached content back to the user’s browser.
- Example: The user’s dashboard is displayed on their screen.
Step 8: Cache Hit (Content Found)
- If Cache Hit: The web server finds the requested content in the cache.
- Action: The server directly sends the cached content to the user’s browser without querying the application server.
- Example: If the user requests their dashboard again, the web server quickly serves the cached version.
Step 9: Cache Expiration and Update
- Action: Cached content has a defined lifespan or may be updated periodically.
- Expiration: The cache may expire after a set period, requiring regeneration of the content.
- Update: New interactions or data changes may prompt an update to the cached content.
- Example: If the user’s profile changes, the dashboard content in the cache will be updated to reflect the latest information.
When is the cache updated?
The cache is updated periodically or when new interactions occur to ensure that the content remains current.
How can I identify static and dynamic content on websites I visit?
- Static Content: Images, videos, and downloadable files.
- Dynamic Content: Personalized recommendations, news updates, and user-specific data.