[web2py] Re: Versioning static files or other options for browser cache reloading
Where are you doing that append? Are you using the standard layout.html? For response.files to work, you need to include web2py_ajax.html in the layout head, after all additions to response.files. Anthony On Thursday, August 30, 2012 12:45:26 PM UTC-4, Yarin wrote: I'm trying to apply a version number to my CSS files as a way to force browsers to load the latest version, but the following examples never get outputted even though they create valid URLs: response.files.append(URL('static','css/main.css', vars=dict(v='1208301' ))) or response.files.append(URL('static','css/main.css?v=1208301')) Why won't these work? Is there a better web2py-way for forcing browser cached files to reload? --
[web2py] Re: Versioning static files or other options for browser cache reloading
Glad to see that anyone cares about that (cache busting). I'm working on that, but it has been posponed a few version away. Back to your problems: the first version should work ok. The second version is not supported, because it becomes actually /myapp/static/css/main.css%3Fv%3D1208301 the ? is escaped and the .css extension is not recognized, so it's not included. BTW: if possible, it's generally better to work with versioned folders e.g. /static/1.2.3/css instead of urls ending in ?something (this will be - hopefully - the behaviour of next web2py's versions). Referenced images in the css work ok with versioned folders, not with ?something urls. On Thursday, August 30, 2012 6:45:26 PM UTC+2, Yarin wrote: I'm trying to apply a version number to my CSS files as a way to force browsers to load the latest version, but the following examples never get outputted even though they create valid URLs: response.files.append(URL('static','css/main.css', vars=dict(v='1208301' ))) or response.files.append(URL('static','css/main.css?v=1208301')) Why won't these work? Is there a better web2py-way for forcing browser cached files to reload? --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
This case is an obvious example. I was only suggesting a better way to handle this kind of problem from a general POV. Both methods work ok, but if you set cache headers far in the future (e.g. handling static files with a webserver like apache or nginx) there is a caveat using the vars method: referenced resources in your css have the same url, so they are not fetched back with the css. With versioned folders, instead, relative references works ok, so if the css is /static/1.2.3/css/main.css and has background: url(../img/someimage.png) the image is fetched at /static/1.2.3/img/someimage.png. On Thursday, August 30, 2012 8:50:26 PM UTC+2, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
what version are you using ? both those notations should work ok (just tested in latest trunk and 1.99.7) Web2py does not have a problem with appended vars, it's only that if you do URL('something', 'othersomething') othersomething is escaped (correctly). Then response.include_files() tries to embed those in web2py_ajax (at least in recent scaffolding apps) and it checks for the file extension of the file to write the correct tags in the head. If the URL is generated with vars or if you append the path without using the URL function it should be ok. Please check also that you have response.optimize_css co. disabled: they somewhat cache around your files for some time. That implementation is buggy in my POV. On Thursday, August 30, 2012 9:38:51 PM UTC+2, Yarin wrote: So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
[web2py] Re: Versioning static files or other options for browser cache reloading
I know you have a pending proposal. let's work on it for web2py 2.1 On Thursday, 30 August 2012 13:27:18 UTC-5, Niphlod wrote: Glad to see that anyone cares about that (cache busting). I'm working on that, but it has been posponed a few version away. Back to your problems: the first version should work ok. The second version is not supported, because it becomes actually /myapp/static/css/main.css%3Fv%3D1208301 the ? is escaped and the .css extension is not recognized, so it's not included. BTW: if possible, it's generally better to work with versioned folders e.g. /static/1.2.3/css instead of urls ending in ?something (this will be - hopefully - the behaviour of next web2py's versions). Referenced images in the css work ok with versioned folders, not with ?something urls. On Thursday, August 30, 2012 6:45:26 PM UTC+2, Yarin wrote: I'm trying to apply a version number to my CSS files as a way to force browsers to load the latest version, but the following examples never get outputted even though they create valid URLs: response.files.append(URL('static','css/main.css', vars=dict(v='1208301' ))) or response.files.append(URL('static','css/main.css?v=1208301')) Why won't these work? Is there a better web2py-way for forcing browser cached files to reload? --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
I swear both the URL(..., vars=) and the non-serialized URLs both aren't working- I'm on 1.99.7, with the code in the right place in front of include web2py_ajax.html, together with all my other working scripts and styles. optimize_css is not enabled, and doesn't appear to be any sort of caching problem. Tested on chrome and safari. No clue.. I'll have to test further on a new project and try to drill down into what's going on- will report back. @Rochacbruno, you said you ran into the same thing. Can you verify? On Thursday, August 30, 2012 4:10:51 PM UTC-4, Niphlod wrote: what version are you using ? both those notations should work ok (just tested in latest trunk and 1.99.7) Web2py does not have a problem with appended vars, it's only that if you do URL('something', 'othersomething') othersomething is escaped (correctly). Then response.include_files() tries to embed those in web2py_ajax (at least in recent scaffolding apps) and it checks for the file extension of the file to write the correct tags in the head. If the URL is generated with vars or if you append the path without using the URL function it should be ok. Please check also that you have response.optimize_css co. disabled: they somewhat cache around your files for some time. That implementation is buggy in my POV. On Thursday, August 30, 2012 9:38:51 PM UTC+2, Yarin wrote: So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
I tested this on a project (maybe web2py version -1.97) response.files.append(URL('static', 'css', args='myfile.css', vars=dict(v=get_random( I dont know if it is working now, but I used the plan html for doing this. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
if you can pack a minimalist app to reproduce I'll be happy to help. On Thursday, August 30, 2012 10:23:36 PM UTC+2, Yarin wrote: I swear both the URL(..., vars=) and the non-serialized URLs both aren't working- I'm on 1.99.7, with the code in the right place in front of include web2py_ajax.html, together with all my other working scripts and styles. optimize_css is not enabled, and doesn't appear to be any sort of caching problem. Tested on chrome and safari. No clue.. I'll have to test further on a new project and try to drill down into what's going on- will report back. @Rochacbruno, you said you ran into the same thing. Can you verify? On Thursday, August 30, 2012 4:10:51 PM UTC-4, Niphlod wrote: what version are you using ? both those notations should work ok (just tested in latest trunk and 1.99.7) Web2py does not have a problem with appended vars, it's only that if you do URL('something', 'othersomething') othersomething is escaped (correctly). Then response.include_files() tries to embed those in web2py_ajax (at least in recent scaffolding apps) and it checks for the file extension of the file to write the correct tags in the head. If the URL is generated with vars or if you append the path without using the URL function it should be ok. Please check also that you have response.optimize_css co. disabled: they somewhat cache around your files for some time. That implementation is buggy in my POV. On Thursday, August 30, 2012 9:38:51 PM UTC+2, Yarin wrote: So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
I think it is now working, I checked the source and there is: if isinstance(item,str): f = item.lower().split('?')[0] if f.endswith('.css'): s += css_template % item elif f.endswith('.js'): s += js_template % item elif f.endswith('.coffee'): s += coffee_template % item elif f.endswith('.less'): s += less_template % item elif isinstance(item,(list,tuple)): So f is splitted by ?, but I have not tested. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
Installed fine. On trunk it's ok for all cases, but for vanilla 1.99.7 the check for ? in globals.py isn't there, so both 2nd and 4th are not working. Incidentally, I had a different scaffolding app for 1.99.7 that didn't use response.include_files(), so that's because it was working for me in 1.99.7. Sorry. On Thursday, August 30, 2012 10:55:10 PM UTC+2, Yarin wrote: Niphlod- here you go, a brand new example app created as follows: 1. Created basic app in admin 2. In layout.html, modified the include styles section as follows: !-- include stylesheets -- {{ response.files.append(URL('static','css/skeleton.css')) response.files.append(URL('static','css/web2py.css')) if response.menu: response.files.append(URL('static','css/superfish.css')) response.files.append(URL('static','js/superfish.js')) pass #response.files.append(URL('static','css/main.css')) # WORKS #response.files.append(URL('static','css/main.css',vars=dict(v='123'))) # DOESN'T WORK #response.files.append('/cache_test/static/css/main.css') # WORKS #response.files.append('/cache_test/static/css/main.css?v=123') # DOESN'T WORK }} {{include 'web2py_ajax.html'}} main.css: * { color:red; } That is it- i've indicated which ones work and which don't. (Incidentally, I and others have had issues installing apps packed on my macbook. Let me know if this app installs for you) Platform: OSX 19.6.8 / web2py 1.99.7 / Chrome+Safari On Thursday, August 30, 2012 4:32:40 PM UTC-4, Niphlod wrote: if you can pack a minimalist app to reproduce I'll be happy to help. On Thursday, August 30, 2012 10:23:36 PM UTC+2, Yarin wrote: I swear both the URL(..., vars=) and the non-serialized URLs both aren't working- I'm on 1.99.7, with the code in the right place in front of include web2py_ajax.html, together with all my other working scripts and styles. optimize_css is not enabled, and doesn't appear to be any sort of caching problem. Tested on chrome and safari. No clue.. I'll have to test further on a new project and try to drill down into what's going on- will report back. @Rochacbruno, you said you ran into the same thing. Can you verify? On Thursday, August 30, 2012 4:10:51 PM UTC-4, Niphlod wrote: what version are you using ? both those notations should work ok (just tested in latest trunk and 1.99.7) Web2py does not have a problem with appended vars, it's only that if you do URL('something', 'othersomething') othersomething is escaped (correctly). Then response.include_files() tries to embed those in web2py_ajax (at least in recent scaffolding apps) and it checks for the file extension of the file to write the correct tags in the head. If the URL is generated with vars or if you append the path without using the URL function it should be ok. Please check also that you have response.optimize_css co. disabled: they somewhat cache around your files for some time. That implementation is buggy in my POV. On Thursday, August 30, 2012 9:38:51 PM UTC+2, Yarin wrote: So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --
Re: [web2py] Re: Versioning static files or other options for browser cache reloading
Got it- I'll be upgrading to 2 so not an issue- thanks On Thursday, August 30, 2012 5:52:00 PM UTC-4, Niphlod wrote: Installed fine. On trunk it's ok for all cases, but for vanilla 1.99.7 the check for ? in globals.py isn't there, so both 2nd and 4th are not working. Incidentally, I had a different scaffolding app for 1.99.7 that didn't use response.include_files(), so that's because it was working for me in 1.99.7. Sorry. On Thursday, August 30, 2012 10:55:10 PM UTC+2, Yarin wrote: Niphlod- here you go, a brand new example app created as follows: 1. Created basic app in admin 2. In layout.html, modified the include styles section as follows: !-- include stylesheets -- {{ response.files.append(URL('static','css/skeleton.css')) response.files.append(URL('static','css/web2py.css')) if response.menu: response.files.append(URL('static','css/superfish.css')) response.files.append(URL('static','js/superfish.js')) pass #response.files.append(URL('static','css/main.css')) # WORKS #response.files.append(URL('static','css/main.css',vars=dict(v='123'))) # DOESN'T WORK #response.files.append('/cache_test/static/css/main.css') # WORKS #response.files.append('/cache_test/static/css/main.css?v=123') # DOESN'T WORK }} {{include 'web2py_ajax.html'}} main.css: * { color:red; } That is it- i've indicated which ones work and which don't. (Incidentally, I and others have had issues installing apps packed on my macbook. Let me know if this app installs for you) Platform: OSX 19.6.8 / web2py 1.99.7 / Chrome+Safari On Thursday, August 30, 2012 4:32:40 PM UTC-4, Niphlod wrote: if you can pack a minimalist app to reproduce I'll be happy to help. On Thursday, August 30, 2012 10:23:36 PM UTC+2, Yarin wrote: I swear both the URL(..., vars=) and the non-serialized URLs both aren't working- I'm on 1.99.7, with the code in the right place in front of include web2py_ajax.html, together with all my other working scripts and styles. optimize_css is not enabled, and doesn't appear to be any sort of caching problem. Tested on chrome and safari. No clue.. I'll have to test further on a new project and try to drill down into what's going on- will report back. @Rochacbruno, you said you ran into the same thing. Can you verify? On Thursday, August 30, 2012 4:10:51 PM UTC-4, Niphlod wrote: what version are you using ? both those notations should work ok (just tested in latest trunk and 1.99.7) Web2py does not have a problem with appended vars, it's only that if you do URL('something', 'othersomething') othersomething is escaped (correctly). Then response.include_files() tries to embed those in web2py_ajax (at least in recent scaffolding apps) and it checks for the file extension of the file to write the correct tags in the head. If the URL is generated with vars or if you append the path without using the URL function it should be ok. Please check also that you have response.optimize_css co. disabled: they somewhat cache around your files for some time. That implementation is buggy in my POV. On Thursday, August 30, 2012 9:38:51 PM UTC+2, Yarin wrote: So it seems like response.files has a problem with appended vars? Even when I spell out the URL entirely, it never gets output: response.files.append(/css/main.css?v=123) # Doesn't get output response.files.append(/css/main.css) # Does get output Assuming this is why rocha used html. Can we fix this at least? Niphlod- Cache-busting- cool, this is what we need. The folder-versioning is annoying to do manually for incremental updates, but if web2py could automate it would be slick. Per that implementation, let's have it as an adjustable setting (e.g. css_version_num) instead of completely randomized per rocha's solution- cache is useful, we just want to bust it when we have an update to roll (probably obvious) On Thursday, August 30, 2012 2:50:26 PM UTC-4, rochacbruno wrote: I cant understand how versioned folders would help on this case? I ran on to this issue a long time ago and I ended using pure html for this. script src={{=URL('static', 'js', args='mylib.js')}}?{{=get_random_number()}} This works for me when I need to bypass the cache to get the proper js loaded on the client. --