Why does CClientScript use recordAction()?

I’m working in a custom clientscript component. Therefore i looked at the source of CClientScript and found, that all register*() calls get recorded by the cache. For example:

    public function registerCssFile($url,$media='')






        return $this;


That means, these methods are replayed, even if a cached version of a page is found. From COutputCache:

    public function init()




        [ ... ]


I don’t really understand, what this is for. As i see it, the cached page content should already have the JS + CSS inserted, because the script tags get inserted before the page is cached. Or am i wrong here?

The only reason i could think of, is, to make sure, that any assets are published again, in case someone cleared the assets folder.

Can someone explain, why these methods are recorded?

This is mainly used when fragment cache is in effect.

For example, if you cache a partial view in which you register some scripts, then when the cached version is rendered, the scripts will still be registered.

That makes sense, thanks Qiang.

But it’s also in effect when page caching is used, right? So it adds some redundancy?