Can an expiration date be set for an html page?

0

People I have an html with an iframe inside where jquery and a webservice charge a voucher in pdf format, the problem is that the first proof that I want to open does well, while the following continue showing the first. I guess it's because the page in question has been cached. Any other suggestions but?

Function js that calls the webservice

function DescargarLiq() {
var url = "../paginas/ws.asmx/DescargarLiquidacion";
var archiv = window;
archiv.open("../paginas/Liquidacion.html", "PDF");
archiv.Ruta = url;
}

The WebService function loads an image stored in the project and through itextsharp completes it with the transaction data

Script within the Liquidation page.html

    $(document).ready(function () {
        var Ruta = window.opener.Ruta;
        crarPDF();

        function crarPDF() {
            $('#iframepdf').attr('src', Ruta);
        }
    });
    
asked by DavidC 07.08.2017 в 13:37
source

1 answer

1

This behavior is controlled by the browser, and it does so mainly based on a series of HTTP headers that are associated in the answer that comes from the server, and that give indications on how to manage the cache :

  • Pragma: no-cache and Cache-Control: no-cache : They tell the browser that the file should not be cached, so you will always need to download the new version in full

  • Expires indicates a time from which the cached copy should be considered invalid and discarded.

  • Cache-Control: max-age = 100 is similar, only that instead of giving the expiration date it indicates how much time is needed for this one.

  • Last-Modified indicates when it was the last time the resource was modified on the server; If the date is after the date of the document in the cache that means that the resource has changed and should be loaded.

All these values are defined on the server , so you must modify the code of the server to include them.

If you can only touch the client code, there is a small "trick" easy to prove: modify the URL so that each request is different, "tricking" the browser in this way so that it never accesses the information cached.

The simplest thing is usually to add a "dummy" parameter to the URL that varies with each request; for example the system time:

var d = new Date();
var url = "../paginas/ws.asmx/DescargarLiquidacion?dummy=" + d.getTime();

Anyway, if you can modify the server it is better to do it there because a) you solve the problem for all the clients that connect and b) it will give less unforeseen problems.

    
answered by 07.08.2017 в 14:01