Indeed a good question, after closely observing the market behaviour, which indicates that the price of a scrip falls straight after the stock becomes ‘Ex-Dividend’ or ‘Post-Dividend’, approximately equivalent to the quantum of dividend. It is also true that the price usually climbs back to the previous level.
Therefore, it really does not make a difference, in the long run whether one buys a scrip before or after it becomes 'Ex-Dividend'. Even in the short term there is no loss and one may gain the dividend income as a bonus, when the price eventually regains its previous level.
The more important question is whether the stock is worth investing in, in the first place? If it is and if you one the money for investment, the sum should be deployed for purchasing the shares immediately. Not deploying the amount earmarked for investment is indeed a serious folly.
Since wealth creation happens only over a very long time, out of innumerable purchases of stocks, receipt of dividends and on the back of the law of ‘Miracle of Compounding’, all the minor variations will be ironed out, and really do not make any difference. One may buy the either before or after it becomes 'Ex-Dividend' and it may be slightly more beneficial to buy before, and I have personally done this a few occasions in the past and after having answered the question seriously considering repeating the scheme of buying immediately after dividend announcement.