Lag, where is the problem?

If by “lag” you mean the page loads slower, this is because you are fetching a remote resource on every page load. Use JavaScript instead to load APIs client-side.