In a large pan, drizzle oil over medium low heat. Once heated, add the sliced onions. Reduce heat to low and cook, stirring occasionally, until a deep purple and caramelized, about 30 minutes. Sprinkle with salt and pepper. Transfer to a medium bowl and allow to cool.
Place a large skillet over medium low heat.
Spread butter over one side of each slice of bread. Cover half of the bread slices with a layer of cheese on the buttered side. Cover the cheese with a thin layer of caramelized onions and a few spinach leaves. If desired, season with some red pepper flakes. Top with another layer of cheese, then the remaining bread slices, butter side touching the cheese. Spread the top of each sandwich with mayonnaise.
Place a sandwich on the heated skillet, mayonnaise coated side down. Spread mayonnaise on the top of the sandwich. Cook until the bottom layer of cheese is melted and bread is golden brown. Flip and cook other side until melted and golden brown.
Serve immediately and repeat with remaining sandwiches.