It was another snag in the return for the 30-year-old Djokovic who was playing in just his second event of 2018 after the Australian Open in January.
"I just completely lost rhythm, everything", Djokovic told reporters afterwards.
On his highly-anticipated return to the tour after right elbow surgery, Djokovic looked a shadow of his former self.
"I'm still not strong enough to go play a match".
Djokovic had four aces but overall he served poorly making four double faults and winning just 65 percent of his first-serve points.
Krajinovic dug deep early, overcoming a 2-0 deficit to level things up but it was one-way traffic from that point as Federer hurried to a one-set lead in the next four games - winning three of them to love.
"I was feeling like he was not loving my slice and I was also mixing in dropshots", said Federer who extended his flawless record this season to 14-0.
Federer was clearly not in the mood to get acquainted with the Serbian, though, running out a comfortable 6-2 6-1 victor in just under an hour.
Federer is making his 17th appearance in the California desert and is assured of remaining world No1 if he makes it to the semifinals.
It took less than an hour for Federer to see off the world No. 28 on Stadium 1, with Jeremy Chardy standing in the way of a place in the quarterfinals.
Federer said he understands well how even a champion like Djokovic could be struggling to find his game so soon after having surgery.
Roger Federer didn't rule out the clay season, at least not yet, he said yesterday at Indian Wells. "When you go away from the game for over a two-month period, it starts feeling a little bit that way".
"Especially in a short spell, you get a lot of looks and you're very inspired".
"But it's not easy to deal with this kind of frustrations after injuries or when you always be the favorite to win a tournament, you come here and you lose in first round".
Britain's Kyle Edmund, who had been out of action with a hip injury since making the semi-finals at the Australian Open lost out to Israel's Dudi Sela.