3 messages in com.googlegroups.opensocial-apiSOLUTION: Work around for cached .js ...| From | Sent On | Attachments |
|---|---|---|
| João Ribeiro | 25 Mar 2008 10:44 | |
| João Ribeiro | 26 Mar 2008 08:41 | |
| João Ribeiro | 26 Mar 2008 08:44 |
| Subject: | SOLUTION: Work around for cached .js files![]() |
|---|---|
| From: | João Ribeiro (joao...@gmail.com) |
| Date: | 03/25/2008 10:44:45 AM |
| List: | com.googlegroups.opensocial-api |
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.




