<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 2, 2013 at 4:20 PM, Rick Bragg <span dir="ltr"><<a href="mailto:rbragg@gmnet.net" target="_blank">rbragg@gmnet.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5"><br>
<br>
><br>
> On 2013-01-02, at 5:35 PM, Puneet Kishor wrote:<br>
><br>
>> On Jan 2, 2013, at 2:27 PM, David Golden <<a href="mailto:xdg@xdg.me">xdg@xdg.me</a>> wrote:<br>
>><br>
>>> On Wed, Jan 2, 2013 at 5:16 PM, Rick Bragg <<a href="mailto:rbragg@gmnet.net">rbragg@gmnet.net</a>> wrote:<br>
>>>> hooks and routes are called once in the application flow. Do I really have to<br>
>>>> program around this taking into consideration the number of times the before<br>
>>>> hook<br>
>>>> is called on each page?<br>
>>><br>
>>> HTTP is stateless. The client can make as many requests as it likes<br>
>>> and your Dancer app will see them as separate requests.<br>
>>><br>
>>> The 'before' hook fires for every request. If you want to limit a<br>
>>> hook to particular routes, you have to write that logic yourself in<br>
>>> the hook subroutine or else wrap the route handlers instead of using a<br>
>>> before hook.<br>
>><br>
>> While the above explanation makes sense, and understanding it can lead to<br>
>> designing applications better, my gut feeling is with Rick. If I create a<br>
>> 'before' hook, I want it normally to fire once everything the human user makes a<br>
>> request even though under the scene the browser is making multiple requests. In<br>
>> other words, the current behavior seems to be against the DWIM nature that I<br>
>> would expect.<br>
>><br>
>> Dancer being the new, easy way of developing apps, should perhaps have two kinds<br>
>> of hooks -- one that behaves the current way, and another that fires the way<br>
>> Rick, myself, and I suspect many other Dancer users expect it to behave, that is,<br>
>> once per human user request.<br>
><br>
> If the before hook is firing on each request for static content (like favicon.ico),<br>
> why even bother serving it up via the app? You can handle that via<br>
> <a href="https://metacpan.org/module/Plack::Middleware::Static" target="_blank">https://metacpan.org/module/Plack::Middleware::Static</a> or in your web server config.<br>
> In most cases you don't even want the app to know about static files.<br>
><br>
> Olaf<br>
> --<br>
> Olaf Alders<br>
> <a href="mailto:olaf@wundersolutions.com">olaf@wundersolutions.com</a><br>
><br>
> <a href="http://www.wundersolutions.com" target="_blank">http://www.wundersolutions.com</a><br>
> <a href="http://twitter.com/wundercounter" target="_blank">http://twitter.com/wundercounter</a><br>
><br>
> <a href="tel:866%20503%202204" value="+18665032204">866 503 2204</a> (Toll free - North America)<br>
> <a href="tel:416%20944%208306" value="+14169448306">416 944 8306</a> (direct)<br>
><br>
<br>
</div></div>I'm using plack and I have apache set up to serve the "public" directory<br>
directly... so... I still don't get why the multiple calls to the before hook...<br>
<span class=""><font color="#888888"><br>
Rick<br>
</font></span><div class=""><div class="h5"><br>
<br></div></div></blockquote><div class="h5"> <br>Are you doing any ajax calls? Or perhaps requests that redirect, for example, are you hitting <a href="http://yoursite/">http://yoursite/</a> which then redirects to <a href="http://www.yoursite/">http://www.yoursite/</a>? Can you print the full URL that's being hit in the call so you can see if it's the exact same URL or something different? As others have mentioned, by default browsers look for that favicon.ico file in your web root, so it doesn't matter if you're serving /public/ through apache, since the request isn't looking for /public/favicon.ico, it's looking for /favicon.ico.<br>
</div><div><br></div><div>I haven't seen any behavior indicating that multiple calls to any hooks happen unless multiple requests are happening, so I think you should keep looking for the cause of the multiple requests, not the same request hitting the hook multiple times. Of course, there could be some bug that I haven't run into, but based on your messages so far, I really think you're dealing with multiple requests coming in "around" the same time. Can you check your request (access) log before and after you hit the page?<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
<br>
<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div></div>