01 - Preheat the oven to 350°F. Grease a 9x13 inch baking dish with butter.
02 - Melt butter in a saucepan over medium heat. Add onion if using and sauté until soft, about 3 minutes. Add garlic and cook for 1 minute until fragrant.
03 - Stir in heavy cream, whole milk, salt, black pepper, and ground nutmeg. Heat gently until steaming but do not boil, then remove from heat.
04 - Arrange half of the potato slices in the prepared dish, slightly overlapping. Pour half of the cream mixture over the potatoes, then sprinkle with half of the cheddar and Gruyère cheeses.
05 - Layer the remaining potato slices on top. Pour over the remaining cream sauce and sprinkle with the remaining cheeses.
06 - Cover the dish tightly with aluminum foil and bake for 45 minutes.
07 - Remove foil and bake for an additional 15 to 20 minutes until the dish is golden, bubbly, and potatoes are tender when pierced with a knife.
08 - Allow to rest for 10 minutes before serving. Garnish with chopped chives or parsley if desired.