Correct way to disable cache (anchor link problem)

272 views
Skip to first unread message

fsund...@gmail.com

unread,
Jan 5, 2016, 5:12:55 PM1/5/16
to spfjs
If I never want SPF to cache any page, is this the correct way to disable the cache or do I need any more parameter?

opt_config = {
'cache-lifetime': 0,
'cache-max': 0
};
spf.init(opt_config);

I have problem with Back button/navigation if the previous link has a anchor link in the URL. Is it related to the cache or something else?

David Phillips

unread,
Jan 5, 2016, 5:29:10 PM1/5/16
to fsund...@gmail.com, spfjs
Either one will work. The caching code immediately bails if either value is <= 0.

I haven't heard of any similar issue with back navigation. Are you saying it fails to find the page in cache, or there's a loading error?


--
You received this message because you are subscribed to the Google Groups "spfjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spfjs+un...@googlegroups.com.
To post to this group, send email to sp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spfjs/9822a4fc-df1b-4338-95a4-dde33c65eb18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Nicksay

unread,
Jan 5, 2016, 5:52:36 PM1/5/16
to David Phillips, fsund...@gmail.com, spfjs
Also, when navigating between two URLs that only differ by the hash, SPF won't make a request, just scroll the page (if possible).

Here's an example of what happens when clicking or going back across some links:

[load]     /foo
[click]    /foo  -->  /bar             (request /bar)
[click]    /bar  -->  /bar#target      (scroll to #target)
[click]    /bar#target  -->  /other    (request /other)
[back]     /other  -->  /bar#target    (request /bar, then scroll to #target)
[back]     /bar#target  --> /bar       (scroll to top)
[back]     /bar  -->  /foo             (request /foo)


What type of problem are you seeing?


- Alex



- Alex

Fredrik Sundqvist

unread,
Jan 5, 2016, 5:54:34 PM1/5/16
to Alex Nicksay, David Phillips, spfjs
If you visit:

Then click on "bring" user. After page navigation, hit "Back" in your browser and it fails to reload page (it get stucks on the user profile).

David Phillips

unread,
Jan 5, 2016, 6:03:09 PM1/5/16
to Fredrik Sundqvist, Alex Nicksay, spfjs
I think this is just an issue with how your servlet handles back button requests.

When a back button is clicked, the cgi param is "spf=navigate-back", instead of "spf=navigate". The response should often be the same, but it's differentiated in case you need to handle back button in unique ways. In your case, it looks like the servlet is probably looking for "spf=navigate" specifically, so the back button returns a full html response, and SPF fails to load it.

David Phillips

unread,
Jan 5, 2016, 6:05:55 PM1/5/16
to Fredrik Sundqvist, Alex Nicksay, spfjs
Alex, it seems like only the default behavior is specified in the docs. Is back button behavior described anywhere at the moment?

Fredrik Sundqvist

unread,
Jan 5, 2016, 6:09:54 PM1/5/16
to David Phillips, Alex Nicksay, spfjs
I don't think it's related to any "navigate-back" because it works if its not any anchor link in URL. Try to remove anchor and it will reload page when you hit Back.


Hälsningar,
Fredrik Sundqvist

David Phillips

unread,
Jan 5, 2016, 6:24:33 PM1/5/16
to Fredrik Sundqvist, Alex Nicksay, spfjs
No, it's definitely related to your servlet code. If you open up chrome developer tools and watch the navigation (make sure to check 'preserve log'), you'll see that the navigate-back transition loads a full page response. The only difference the anchor makes, is that without the anchor, SPF reloads automatically, but with the anchor, it doesn't.

That's certainly a related issue, as it should always trigger a reload if the request failed, but that's not the core of your problem.

Try adding 'spf=navigate' and 'spf=navigate-back' to your URLs and make sure you're returning the JSON response that SPF expects.

Fredrik Sundqvist

unread,
Jan 5, 2016, 6:31:13 PM1/5/16
to David Phillips, Alex Nicksay, spfjs
All right, I see. In this case I haven't enabled spf on the "thread view", only start page and profile page. But the goal is to enable SPF on that "thread view" too, I just need to rewrite som javascript first. But yeah, probable should work the same way with anchor link as without.


Hälsningar,
Fredrik Sundqvist

David Phillips

unread,
Jan 5, 2016, 6:40:37 PM1/5/16
to Fredrik Sundqvist, Alex Nicksay, spfjs
Definitely. I filed https://github.com/youtube/spfjs/issues/377 to track the issue. Hopefully it'll be a quick fix.

Alex Nicksay

unread,
Jan 5, 2016, 8:29:24 PM1/5/16
to David Phillips, Fredrik Sundqvist, spfjs
Documenting the URL identification (for standard vs back requests etc) is tracked in https://github.com/youtube/spfjs/issues/262.

I just filed https://github.com/youtube/spfjs/issues/378 to track documenting the anchor link behavior I described earlier in the thread.

- Alex

Alex Nicksay

unread,
Jan 6, 2016, 6:16:23 PM1/6/16
to David Phillips, Fredrik Sundqvist, spfjs
Hi Fredrik,

A fix has been committed to master (https://github.com/youtube/spfjs/pull/380).

If you're using a release as described at https://youtube.github.io/spfjs/download/, we'll be releasing a new version on Friday with the fix.  Otherwise, if you're building from source, you can update and test the changes now.

Thanks,
Alex


- Alex

Fredrik Sundqvist

unread,
Jan 7, 2016, 7:32:05 AM1/7/16
to Alex Nicksay, David Phillips, spfjs
Great! Thank you!


Hälsningar,
Fredrik Sundqvist
Reply all
Reply to author
Forward
0 new messages