Skip to main content

Re-render media on page load/reload

Comments

7 comments

  • Zendesk API User
    Author: felix_reinhold - 5/9/2019 8:24

    Hi Dragan,

    I had a similar issue once. For me it was just the normal server caching. Have you tried adding a random request param when opening the file? I just added the lastChange timestamp to all refs of parsed media in preview/cc.

    Best regards

    Felix

    0
  • Zendesk API User
    Author: draganr - 5/10/2019 9:44

    Hi Felix,

    I have tried the following, but still the same.

      <script id="download-search-js" type="text/javascript" src="$CMS_REF(media:"downloadsearch", abs: 2)$" $CMS_IF(#global.preview)$data-last-change="$CMS_VALUE(ref(media:"downloadsearch").getMetaData().revision.getCreationTime)$"$CMS_END_IF$></script>

    I have also tried with #global.now, but no success.

      <script id="download-search-js" type="text/javascript" src="$CMS_REF(media:"downloadsearch", abs: 2)$" $CMS_IF(#global.preview)$data-last-change="$CMS_VALUE(#global.now.milliseconds)$"$CMS_END_IF$></script>

    Sorry, but do you maybe have an example?

    Regards,

    Dragan

    0
  • Zendesk API User
    Author: felix_reinhold - 5/10/2019 10:00

    Hi Dragan,

    you should add the timestamp as GET-param

    $CMS_SET(mediaRef, ref(media:"downloadsearch", abs: 2))$

    <script id="download-search-js"  type="text/javascript" src="$CMS_VALUE(mediaRef.url)$$CMS_IF(#global.preview && ps_debug)$?_t=$CMS_VALUE(mediaRef.target.revision.getCreationTime())$$CMS_END_IF$"></script>

    or you could try it with forceRefresh (don't know if servlet listenes to this param for media)

    $CMS_SET(mediaRef, ref(media:"downloadsearch", abs: 2))$

    <script id="download-search-js"  type="text/javascript" src="$CMS_VALUE(mediaRef.url)$$CMS_IF(#global.preview && ps_debug)$?forceRefresh=1$CMS_END_IF$"></script>

    If this works for you then you should check, if there are already get-params in the url and change use "&" or "?" for th eurl depending on the result.

    best regards

    Felix

    0
  • Zendesk API User
    Author: draganr - 5/10/2019 11:55

    Hi Felix,

    I have tried something similar before:

    <script type="text/javascript" src="$CMS_REF(media:"downloadsearch", abs: 2)$?v=$CMS_VALUE(#global.now.milliseconds)$"></script>

    Now I also tried your suggestions, but still the same. It loads changes after 30 minutes.

    This is the way it's called inside downloadsearch.js

    var downloadSearch = (function () {

        var jsondata = $CMS_RENDER(template:"ft_downloads_json")$;

            .....

    })();

    Regards,

    Dragan

    0
  • Zendesk API User
    Author: felix_reinhold - 5/10/2019 12:37

    HI Dragan,

    just created a small PoC and sadly I can't avoid the caching aswell.

    Maybe sth. has changed in the PreviewServlet or I just didn't remember correctly.

    Maybe there's another parameter that can be used. Otherwise the only solution I can come up with would be to move the download.js to a PageTemplate instead of a File.

    Best regards

    Felix

    0
  • Zendesk API User
    Author: Nitros - 5/13/2019 8:43

    I am assuming this is about the preview.

    Is there any reason to put the JSON inside a JS file? You could just put it into a script tag:

    <script id="data" type="application/json">$CMS_RENDER(template: "ft_downloadJSON")$</script>

    Wherever you need the data just read it from the tag:

    function loadJsonFromDocument(id) {

        const element = document.getElementById(id);

        return JSON.parse(element.innerHTML);

    }

    I do that quite a lot and never had issues.

    What I assume is happening here is that the preview get's confused. You already need to use force refresh with format templates in a lot of cases. If you add a JS file as well it just get's more complicated.

    If it's really important I would try to simplify the data transfer and not mess with the preview servlet cache. Also, just to make sure, you did use force refresh by holding SHIFT when opening the preview? You should see a forceRefresh=1 in the preview url.

    0
  • Zendesk API User
    Author: draganr - 5/29/2019 10:06

    Hi Felix, hi Nitros,

    Thanks for your help, I'll use it in a different way.

    Kind regards,

    Dragan

    0

Please sign in to leave a comment.