How to request Browser Cache Controll for Webpage ?
SEO Help and Tips
How to request Browser Cache Controll for Webpage ?
Website Cache controll system will boost up the speed of website:
Html Code:
<meta content='max-age=5092000' http-equiv='Cache-Control'>
In the above code, max-age=2592000 sets the caching duration to 30 days (in seconds). This tells the browser to cache the resource for 30 days and retrieve it from the cache on subsequent visits.
Remove this tag from Head (<meta content='0' http-equiv='Expires'>) It will not allow to store Cache
<meta http-equiv="Cache-Control" content="public, cache, must-revalidate, max-age=15294000">
public:
Indicates that the response may be cached by both the browser and intermediate caching systems.
cache:
Allows the browser to cache the response.
must-revalidate:
Instructs the browser to revalidate the cached copy with the server before using it, ensuring it is still valid.
max-age=15294000: Specifies the maximum time in seconds that the cached copy can be considered fresh before revalidation is required. In this example, it is set to approximately 6 months (60 seconds * 60 minutes * 24 hours * 175 days).
Java:
<script type='text/javascript'>
//<![CDATA[
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Set cache headers for public caching
int maxAgeSeconds = 3600; // Set the desired maximum age in seconds
response.setHeader("Cache-Control", "public, max-age=" + maxAgeSeconds);
response.setHeader("Expires", calculateExpirationTime(maxAgeSeconds));
// Other code to generate and send the response
// ...
}
private String calculateExpirationTime(int maxAgeSeconds) {
// Calculate the expiration time based on the current time and the maxAgeSeconds
long currentTimeMillis = System.currentTimeMillis();
long expirationTimeMillis = currentTimeMillis + (maxAgeSeconds * 1000L);
return HttpDate.format(expirationTimeMillis);
}
}
//]]>
</script>
Comments
Post a Comment
Thanks for your Comments.