Running workers conditionally

Is it possible to run the worker conditionally and not for every incoming request?
In my case, I'd like the worker to run only for document (html) requests, meaning for every request pathname that does not include a period (since having a period in the pathname means directly requesting a file).
Was this page helpful?