How to load absolute CSS and JS assets
Even though you don't want to use a contrib module I will recommend the CDN module anyways. It does what you want, but if you don't want to use it you can still look at how they do it.

They define a lot of services, but the most interesting one is this one:

cdn.file_url_generator:
    class: Drupal\cdn\File\FileUrlGenerator
    arguments: ['@app.root', '@file_system', '@stream_wrapper_manager', '@request_stack', '@private_key', '@cdn.settings']


The class FileUrlGenerator then does checks for files to determine if they should be rewritten and rewrites them.