Dear all,

I came across a caching problem while developing open social
applications.
I included a .js file like this in my widget xml file:
 <script src="host/bogusWidget.js"></script>

Every time I changed some code on bogusWidget.js file, the change
wasn't immediatly reflected so I needed to wait for the cached request
to clear.

This is the workaround I build for this, maybe it can help others with
the same problem.

Here's a complete widget definition including a bogusWidget,js file
that never gets cached:

<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Bogus Widget">
    <Require feature="opensocial-0.7"/>
  </ModulePrefs>
  <Content type="html">
    <![CDATA[

      <script>

        function include_dom(script_filename) {
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', script_filename);
        html_doc.appendChild(js);
        return false;
        };

        function includeScript(url) {
            var refreshInterval=0;
            var ts = new Date().getTime();
            var sep = "?";
            if (refreshInterval && refreshInterval > 0) {
                ts = Math.floor(ts / (refreshInterval * 1000));
            }
            if (url.indexOf("?") > -1) {
                sep = "&";
            }
            url = [ url, sep, "nocache=", ts ].join("");

        include_dom(url);
        }


        includeScript("host/bogusWidget.js"); //Use this function
instead of <script src="host/bogusWidget.js">

      </script>
      <script>
        gadgets.util.registerOnLoadHandler(init); //Calling init
method defined somewhere in bogusWidget.js file
      </script>
    ]]>
  </Content>
</Module>


I hope this helps, its a solution mixing some DOM manipulation and the
caching workround found in the API documentation for
gadgets.io.makeRequest() return values.

Best regards,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OpenSocial Application Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to