The former champions both advanced to the third round Thursday, two days after their opening matches ended early when their opponents retired with an injury.
In his opening two matches at the All England Club, Djokovic has lost only eight games.
"It's perfect. Exactly what I want," Djokovic said. "I don't want to have any five-set matches in there."
It was the second match for Djokovic with Andre Agassi and Mario Ancic as his coaches, both of whom were in the coaches' box at No. 1 Court.
Djokovic won the Wimbledon title in 2011, 2014 and 2015. But he has not won a major title since completing a career Grand Slam at the 2016 French Open.
Lajovic opened up a 2-0 lead by breaking Federer in the second game on Centre Court, but Federer broke right back and then dominated the tiebreaker.
Federer won the Australian Open this year but skipped the French Open. He is looking to win a record-breaking eighth men's title at the All England Club.
Darcis is the eighth man to retire during a match this week. He took a medical timeout after 18 minutes of play and was unable to continue.
Get better soon, Steve Darcis, who became the eighth men's player to retire from these Wimbledon Championships. It's Day 4, and we're only two men's retirements away from tying the most here in the Open era.
A Belgian ranked 61st, Darcis is best known for beating Rafael Nadal in the first round at Wimbledon in 2013 only to withdraw before his next match, citing an injured right shoulder.
Ferrer was a quarterfinalist at the All England Club in 2012 and 2013. His best Grand Slam showing was a runner-up finish at the 2013 French Open.
American John Isner is out of the tournament, as the No. 23 seed lost to Dudi Sela 6-7 (5), 7-6 (5), 5-7, 7-6 (5), 6-3. Isner has yet to make the second week at the All England Club and is 4-15 in five-set matches since his famed 2010 first-round match at Wimbledon that ended 70-68 in the final set.
The 6-foot-10 Isner had quite a height advantage over the 5-9 Sela, but that didn't help on this day. Isner clocked 45 aces in the match but couldn't win any of Sela's service games in the fifth set, going 0-for-6 on break points.
Isner said he was "very, very disappointed" by the loss.
"It's all between the ears, I think," Isner said. "I had opportunities, of course. When I don't go for it, bad things happen. That was the case throughout the whole match, me not going for it. That's why I lost."
ESPN's Matt Wilansky and The Associated Press contributed to this report.