Preheat your oven to 375°F (190°C). Grease a 9x9-inch(or similar size) baking dish with the butter
Thinly slice the potatoes. You can use a mandoline slicer for even, thin slices. Wash the potatoes to get rid of the excess starch and let it sit in a bowl of water to prevent browning
Caramelize one sliced onion in a pan with oil/bacon grease. Set aside in a bowl. In the same pan, prepare the cheesy sauce by adding 3 tablespoon butter, Sauté finely chopped garlic and add all-purpose flour. After the mixture turns light brown, add milk, 1 cup cheddar cheese, rosemary and salt to taste. Mix it well with a rubber spatula until you get a thick cheesy consistency
Start by layering three-forth of the sliced potatoes in the bottom of the prepared baking dish, overlapping them slightly. Sprinkle salt, bacon bits and caramelized onions evenly over the potatoes
Add the cheesy sauce over the potatoes to coat the entire pan. Layer over the remaining potatoes and sprinkle some more salt. Cover the baking dish with aluminum foil and place it in the preheated oven. Bake for about 45 minutes
Remove the foil, Sprinkle the Gruyère cheese / white cheese and thyme evenly, and bake for an additional 25-30 minutes or until the potatoes are tender, the top is golden brown, and the cheesy sauce is bubbling around the edges
Remove the dish from the oven and let it rest for a few minutes before serving. This allows the sauce to thicken slightly. Serve it hot as a delicious side dish