01 - Preheat 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 cook until softened, about 3 minutes. Stir in garlic and cook 1 minute until fragrant.
03 - Add heavy cream, whole milk, salt, black pepper, and nutmeg to the saucepan. Warm gently until steaming without boiling, then remove from heat.
04 - Arrange half of the sliced potatoes in the baking dish, overlapping slightly. Pour half the cream sauce over the potatoes and sprinkle half the cheddar and Gruyère cheeses evenly.
05 - Add remaining potatoes in an even layer. Pour the rest of the cream sauce on top, followed by the remaining shredded cheeses.
06 - Cover dish tightly with aluminum foil and bake for 45 minutes.
07 - Remove foil and continue baking 15 to 20 minutes until potatoes are tender, cheese is golden and bubbly.
08 - Let stand for 10 minutes before serving. Garnish with chopped fresh chives or parsley if desired.