The end result was another defeat. But rather than trudging up the road for another evening of rumination and recriminations, Heart of Midlothian supporters could be forgiven for returning home from Glasgow with the slightest hint of a spring in their step.

For the longest time on Sunday, it appeared as though Hearts were on track for the morale-boosting statement win that fans have craved to see from Steven Naismith’s team. It had been the best part of a decade since the men in maroon had recorded a league victory at Ibrox, and Hearts couldn’t have been much closer to bringing that record to an end. But it wasn’t to be.

If the previous week’s 4-1 defeat at home to Celtic provided a sobering lesson about how far this team still has to go, then Sunday’s loss to Rangers demonstrated that the situation isn’t quite as bleak as the game against the champions indicated. In both fixtures, Hearts left with nothing to show for their exertions – but the two performances could hardly be more stark.

Against Celtic, Hearts were off the pace from the get-go. The team’s shape allowed Brendan Rodgers’ side to dominate in midfield and didn’t offer the defence enough protection. Throw in a few individual errors at the back and a general struggle to build up and create any sort of meaningful attack – for the first 70 or so minutes, at the very least – and it isn’t difficult to see why that contest ended up being so one-sided.

READ MORE: Rangers 2 Hearts 1 | Instant analysis: Caution, formation and in-game decisions

That loss led to plenty of soul-searching in the build-up to the trip to Ibrox. Was Naismith cut out to manage a club of Hearts’ stature? Did he possess the tactical nous to take points off the Old Firm? Are the players capable of punching up, of going up against one of the big boys and leaving them with a bloody nose?

Any Hearts manager worth their salt needs to take points off of Glasgow’s big two if they are serious about firmly establishing the club as Scotland’s third force and ultimately closing the gap with the Old Firm. Competing, even without winning, is the minimum requirement. And Sunday’s defeat in Govan, as much as it still stings, showed that Naismith’s side can do just that.

Lessons had been learned from the loss to Celtic. Naismith changed the shape as he opted for a more conservative 5-3-2 formation. The back three of Kye Rowles, Frankie Kent and Toby Sibbick were shielded by Beni Baningime at the base of midfield, and the two wing-backs sat deep to limit space on the flanks for Rangers. With Calem Nieuwenhof and Jorge Grant also dropping deep and drifting wide, Rangers quickly ran out of space when they advanced into the final third.

The set-up added an extra layer or two of defence at the back, but there was an obvious downside too: where were the goals going to come from? Hearts would have to get bodies forward when the opportunity arose to prevent Kenneth Vargas and Lawrence Shankland from becoming isolated in attack. Here we would see another key change from the Celtic loss: mentality.

Naismith has regularly spoke about the need for players to be braver on the ball, to be more adventurous when attacking the opposition, and Shankland’s fifth-minute goal showed why the former Scotland internationalist is so keen to get that message across. Hearts won a throw-in in Rangers’ half but committed men forward so that the man in possession always had options. The result? A sublime cross from Alex Cochrane that was expertly nodded in by Shankland at the back post.

The remainder of the first half was played in a predictable pattern. Rangers had plenty of the ball but not many ideas about what to do with it, while Hearts enjoyed a few decent spells of possession and exploited spaces on the pitch well. They were aided by Rangers’ apparent refusal to press high up the park but they did a fine job of stifling their opponents while still offering a threat at the other end. The fans in the home end made their feelings known as the grumbles and groans grew louder with every misplaced pass or speculative shot gone awry, and they could have few complaints about the score when the half-time whistle rang out. Shankland’s goal-saving clearance off the line and James Tavernier’s missed penalty might suggest Hearts were lucky to be ahead but the truth was that Naismith’s men were good value for their lead.

It became a lot more one-sided during the second half, particularly as the match wore on and the tension ratcheted up. Hearts now seemed happy to hold what they had and to resolutely defend their one-goal lead without really trying to increase it. The occasional spells of possession became rarer and rarer, and it soon became apparent that a backs-to-the-wall approach would be in place for the game’s frenetic finale.

But Hearts held firm. Zander Clark had been tested by a few pot-shots but the goalkeeper hadn’t been called into action all that much, given the circumstances. Rangers were knocking on the door without much success – until a moment of madness caused Hearts’ undoing. Connor Goldson tumbled to the floor at a corner kick and after reviewing the footage at the pitchside monitor, referee John Beaton ruled that Peter Haring had hauled him to the floor. Tavernier made amends for his earlier miss by restoring parity from the spot just as the stadium announcer revealed there would be an additional eight minutes of stoppage time to be played. The crowd roared and the momentum had irrevocably shifted. Hearts’ siege had finally been broken.

READ MORE: Steven Naismith Rangers Q&A: Penalty decision, blocking in box and positives

Danilo’s winner for Rangers a few minutes later had a degree of inevitability about it, but the Hearts players could return to the capital with their heads held high. For 90 minutes, they had looked the part against Rangers and they couldn’t have come much closer to recording a famous victory.

“We played really well, we understood how the game could play out,” Naismith explained. “It went the way we expected. Second half we knew they would take more risks. We knew we would have to defend well and be resolute to frustrate them. We did that - and then the game hinges on the penalty, for me. The whole game hinges on the penalty decision.”

It’s hard to disagree. Naismith felt aggrieved by the referee’s call and even if replays have shown that Rangers probably did have a case in this instance, it shifted the game’s momentum nonetheless and rejuvenated a Rangers side that had looked to have run out of ideas.

“We were defending well, comfortable in possession, so the game plan did work,” Naismith noted. “The contrast from last week to this week is really good. Last week was not acceptable, we were honest about that. This week it was different, much clearer. We knew we needed to be brave on the ball, we did that. And at moments you need to defend, Rangers were resorting to cross balls, shots from the edge of the box that didn't really trouble us. So that's why there's so much disappointment.”

Naismith and his players can take heart from the performance, if not the result, against Rangers. The head coach now has a blueprint for Sunday’s League Cup semi-final against Phillipe Clement’s side and for large spells of the match at Ibrox, it proved to be an effective ploy. Both fixtures ended in defeat for Hearts but as Naismith says, the contrast in the performances could hardly be greater.

Supporters went into these games needing something to believe in, to see some signs of progress and evidence that their team was on the right track. And Naismith has given them exactly that.