If I want then to rename factory in the editor to any other name (like "spare_parts_factory) I also need to refactor the script because otherwise, it contains the wrong url. Is there any other way to get a component id except just hard-coding string, so I wouldn’t need to rename it in all the places I use it during refactoring? Otherwise, it becomes very tedious and difficult to refactor if a component is referenced from many places.
If you are using it multiple places in the same script, then you should save the url string to a variable so you only have to change it in one place at the top of your script. Really you should do this for any constant value that you might ever possibly want to adjust.
If you are using the factory from other scripts, you can do the same for them.
Otherwise, just use search and replace (Ctrl+E in the Defold editor) and click “Replace All”. It should only take a couple of seconds.