Having issue with running onready script in published site!

Yup, you are running into the timing problem on the postMessage. Basically, you are sending data before the component has loaded. Read that article.