Should I create a slug on the fly or store in DB?

后端 未结 4 421
有刺的猬
有刺的猬 2020-12-24 08:33

A slug is part of a URL that describes or titles a page and is usually keyword rich for that page improving SEO. e.g. In this URL PHP/JS - Create thumbnails on the fly or st

4条回答
  •  猫巷女王i
    2020-12-24 09:07

    You might need to take another thing into consideration, what if you want the user/yourself to be able to define their own slugs. Maybe the algorithm isn't always sufficient.

    If so you more or less need to store it in the database anyhow.

    If not I don't think it matters much, you could generate them on the fly, but if you are unsure whether you want to change them or not let them be in the database. In my eyes there is no real performance issue with either method (unless the on-the-fly generation is very slow or something like that).

    Choose the one which is the most flexible.

提交回复
热议问题