[SalesForce] How does rendered/rerender work in Visualforce

This is not about walking out a particular scenario. It's all about my curiosity. I am just wondering how does rendered/rerender work behind the scene. My first understanding was it stores the related info in view state and read that using javascript to hide/show the related content. But that doesn't seem to be true. When I view the html file in developer tools the rendered hide elements are not there instead of showing something like display: none. So how is that done and how fast is the process?

Best Answer

Without getting terribly technical, Visualforce is essentially implemented as JSP; the Visualforce markup is compiled into JSP and run by the Java runtime that renders all of salesforce.

The reason why you don't see hidden elements is because the html is rendered server-side, then delivered to the client JavaScript, which basically drops the compiled code directly into the render targets.

The code runs at about the same speed as native JSP pages, which isn't saying much. You can expect a maximum speed of about 100-200 ms for simple pages. In practice, any page that's worth doing will take close to a second from the initial request to the final rendered state.

I've done benchmarks on this. By using pure client-side rendering and using remote functions can execute the same logic up to 500 percent faster. For example, a Page that takes 100 ms to render using markup can render in 20 ms with a remote action and JavaScript.

The remaining time includes sending the view state, deserializing, serializing, and rendering, plus the additional bandwidth costs, which are most noticeable on slow or laggy connections.

The new, experimental server-side view state feature should bring the entire lifecycle down in response time, but I wouldn't consider that a panacea for all slow Visualforce pages.