move preview script in separate file - serialize before postMessage