You may want to look at the cache examples, as they are doing something similar.
On Thursday, August 7, 2014 1:50:47 PM UTC-7, mweissen wrote: > > Thanks for the detailed explanation. > > What is the idea? > Let's say there are 30 persons in a lecture. Every person is a user of the > my website. But the pages of the presentation should not be presented all > at once. A new page becomes visible at the moment I give it free. Therefore > every client should ask once a second if there is a new page. But it would > be a lot of traffic if every user gets the actual page once every second. > Therefore I want to control whether a page should reload or not. > > Now I have tried a very simple version of "mytime": > > def mytime(): > jetzt=str(request.now)[:19] > if jetzt[18]!="0": > response.status = 304 > return dict(jetzt=jetzt) > > This function shows every 10 secondes the actual time for 1 second. This > is not the solution I am looking for: the last time value should stay for 9 > seconds - but during these 9 seconds the field is empty. > > I think it is a step in the right direction. > > > 2014-08-07 21:10 GMT+02:00 Niphlod <[email protected] <javascript:>>: > >> technically LOAD uses a GET, so returning the correct cache headers with >> a correct status **should** (read, every browser has its own >> implementation) avoid "fragment" (i.e. web2py component) refreshes. But if >> you return the same Etag with a 200 response with a content, the browser >> WILL replace it (you did anyhow request a refresh with an ajax call AND >> you're returning a content, it will be shameful to discard it). If you >> return a 304 with no content than the fragment shouldn't be replaced. >> This, however, is the theory. In practice, javascript has NO ACCESS to >> the etag (or cache) informations the browser has, so ajax doesn't work >> EXACTLY as normal browser GETs. You may even get around it, but then you'll >> be facing various browser implementations of it.... >> >> BTW, there is plenty of docs around the interwebs, such as >> http://juristr.com/blog/2013/06/caching-jquery-ajax-and-other-ie-fun/ >> >> What do you need this for ? isn't zillion times easier just to cache the >> response and send it ? >> >> >> On Thursday, August 7, 2014 7:19:40 PM UTC+2, mweissen wrote: >> >>> Thank you for this information. Shall I use a jquery.ajax-call or can I >>> use the LOAD-helper? >>> >>> >>> 2014-08-07 11:24 GMT+02:00 Niphlod <[email protected]>: >>> >>> if you trigger an ajax request, if it's a GET (an idempotent method) you >>>> may avoid reloading the page and get back a 304....................but >>>> it's >>>> not handled automatically by web2py unless the content is static. >>>> >>>> >>>> On Thursday, August 7, 2014 7:52:30 AM UTC+2, mweissen wrote: >>>>> >>>>> Dave told me that my explanation was not clear. Let me try it in other >>>>> words. What I want is a program which periodically reloads a page (I >>>>> think >>>>> using LOAD is the best way), but only if I allow it. >>>>> >>>>> My idea was that the header parts "Last-Modified" and/or "ETag" could >>>>> do the job. Therefore I wrote the program in two steps: >>>>> >>>>> (1) A controller without any response header modification. It shows >>>>> the actual time and reloads once a second - everything is fine. >>>>> >>>>> The functions: >>>>> >>>>> def mytime(): >>>>> jetzt=str(request.now)[:19] >>>>> return dict(jetzt=jetzt) >>>>> >>>>> def init(): >>>>> return dict() >>>>> >>>>> ------------------------- >>>>> >>>>> The views: >>>>> >>>>> mytime.load: >>>>> {{=jetzt}} >>>>> >>>>> init.html: >>>>> {{extend 'layout.html'}} >>>>> {{=LOAD(f="mytime.load", ajax=True, timeout=1000, times="infinity")}} >>>>> >>>>> >>>>> >>>>> (2) Now I want to simulate an unchanged page. Anthony wrote on >>>>> http://stackoverflow.com/questions/14515313/how-to-modify- >>>>> web2py-download-function-to-return-304-not-modified-in-case-the how >>>>> to change the header. I add the response.headers-lines with a *constant >>>>> *"Last-Modified" time and/or a *constant *"ETag" (I think every value >>>>> is allowed here). My hope has been that these modifications *would >>>>> prevent a reload* of the page. If this would be correct I would >>>>> always see the same time. But it did not work, regardless of the header >>>>> modifications the page reloads again once a second. >>>>> >>>>> def mytime(): >>>>> jetzt=str(request.now)[:19] >>>>> mtime = "Mi, 06 Aug 2014 08:11:00 GMT" # always the same time! >>>>> >>>>> *response.headers['Last-Modified'] = mtime* >>>>> >>>>> * response.headers['Pragma'] = 'cache' response.headers['Cache-* >>>>> *Control'] = 'private' response.headers['ETag'] = "123" # any >>>>> value, constant* >>>>> return dict(jetzt=jetzt) >>>>> >>>>> >>>>> My primary problem is: the LOAD helper (or an other command?) asks the >>>>> server periodically if there is a new content - and the server should >>>>> reload the page under program control. >>>>> >>>>> Is it possible to solve it using the response headers? >>>>> >>>>> The purpose of the request.now call is only to show whether the page >>>>> reloads or not. >>>>> >>>>> Regards, Martin >>>>> >>>>> - >>>>> >>>> >>> >>> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

