Slice the onions thinly and shred the Gruyere cheese if needed. Set out the bread, mayonnaise, and Dijon mustard so everything is ready for assembly.
Heat 1 tablespoon of the butter and the olive oil in a large skillet over medium heat. Add the sliced onions, salt, and black pepper, then stir to coat.
Cook the onions for 20 to 22 minutes, stirring often and lowering the heat as needed, until they are very soft, deeply golden, and caramelized. If the pan starts to brown too quickly, add 1 tablespoon of water and continue cooking until the onions are jammy and evenly colored.
Transfer the onions to a bowl. Wipe out the skillet if needed so the sandwiches toast evenly.
Spread the mayonnaise on one side of each bread slice. Spread the Dijon mustard on the uncoated side of 4 bread slices.
Divide half of the shredded Gruyere over the mustard-coated bread slices. Top evenly with the caramelized onions, then add the remaining Gruyere. Close each sandwich with the remaining bread slices, keeping the mayonnaise-coated sides facing outward.
Heat the skillet over medium-low heat and add the remaining 1 tablespoon butter. When the butter melts, place 2 sandwiches in the skillet and cook for 3 to 4 minutes per side, pressing gently with a spatula, until the bread is deeply golden and crisp and the cheese is fully melted.
Repeat with the remaining sandwiches, adding a small extra dab of butter only if the pan looks dry. Adjust the heat as needed so the bread browns steadily without burning before the cheese melts.
Let the sandwiches rest for 1 minute, then slice and serve hot.