Add timing function to js middleware