On Which Page? Site Pagination from Scratch

I’ve learned recently something I was hoping was over: different browser versions store or not the session cookies. The problem is that even the newest browsers can’t store session cookies or simply refuse them on default settings or with session cookies enabled.Yesterday I rediscovered this problem with Opera, latest stable version, on a Windows XP SP3 PC, trying to fix some client’s pagination problems. My client was completely upset about that even if we assured him we can fix that ASAP. We managed to fix the problem in a matter of hours, in a week-end day. When we build a site, we try to test it on various machines with various hardware and software configurations, but, due to a large number of possible configurations, there still is a possibility to miss the client’s configuration. To eliminate that issue, from now on we emulate a machine similar to the client’s machine on which we test our solutions.

The Pagination Problem

The pagination on the client’s site was using a session cookie to store the current page number and then that number in the session cookie was supposed to be incremented by 10:
 1: '... somewhere in the code we assigned the "pag" cookie a value
 2: Session("pag") = 1
 3: '... some more code here ...
 4: currentPag = Session("pag")
 5: '... currentPag increments and Session("pag") gets updated
 6: currentPag += 10
 7: Session("pag") = currentPag
Ok, now that’s not the whole code, just some example from the top of my mind to illustrate the use of that session cookie. Apparently this session cookies was not supported by the good old Opera Browser on my client’s computer. The first fix that came to my mind was… use a cookie. That didn’t work either!

That’s Why They Use URL Params

So that’s why they use URL parameters, right? The problem was finally fixed as soon as we implemented the page parameters. Of course we had to add some more code and make some small changes to the master page to accept that params and work with them as it should, but we managed to use the old code (read “functions and events”) and everything is working now.

The Lesson Learned

If you want to do pagination from scratch be aware that browsers don’t like session cookies and they treat session cookies in different ways. Better use URL parameters then cookies. The only thing cookies are good when doing pagination is to keep you full while developing using URL parameters. But, if you don’t like the way URLs look after a long number of parameters, group them, split them inside your code and use URL rewrite, resulting in a beautiful user/search engine friendly URL. Cheers,

Despre Răzvan

Răzvan este antreprenor online, developer, tată, soț, consultant pentru companii din România și din afara țării, maker, public speaker, consultant pe probleme de productivitate, podcaster și blogger. Deține de asemenea câteva branduri, printre care: Burzcast™, Burzware™, Burz Media™, Dev-Vision™ și altele.

Participă cu un comentariu

Îți mulțumesc pentru că ai fost alături de mine până aici. Ești super și te apreciez!

Dacă dorești să continui șă citești conținutul blogului Burzcast, iată mai jos un articol pe care poate încă nu l-ai văzut: