Difference in App behaviour when using pn.serve(...) and running panel serve ... from command line

The way I think about it is when you run python -m panel serve app.py, then app.py is fully loaded on each refresh of the user session. (see pn.state for more information also)

But, when you use pn.serve you are serving user sessions into panels application/cache state. I prefer to serve up a function to be called on each refresh. Where I declare the class and a function within it that returns the template (parent Panel component) to be used; and then create a function that instantiates the class and call the template function and use that to associate with the route.

There is more information on pn.serve and routes here also, Option #2: Multi page app documentation - #3 by Marc

Hope that is helpful.