-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access Static Resources And Compile Into Executable #516
Comments
There are saveral options controlling accessing static resources in drogon.
please refer to the comments in the configuration file. |
Thank you, I should have looked more closely at the config file.
…On Tue, Jul 21, 2020 at 9:51 PM An Tao ***@***.***> wrote:
There are saveral options controlling accessing static resources in drogon.
"document_root"
"locations"
"static_files_cache_time"
please refer to the comments in the configuration file.
for example of the jquery file. you could set the "document_root" to
somewhere, etc. "/usr/local/www" and store the js file as
"/usr/local/www/static/javascript/jquery.min.js"
the locations option controls more behaviors of accessing static resources.
the use_sendfile, use_gzip, use_brotli, gzip_static and br_static options
are also related to static files. please see the configuration file.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#516 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQEHCE2BQN624EQRTWLTGGTR4ZA3LANCNFSM4PEAJK7Q>
.
|
@sardar01 Regarding your first question about static assets @an-tao already answered the question. Regarding your second question: Drogon currently doesn’t have any sophisticated asset handling. I’m working on better CDN support for assets & adding preprocessor pipelines for CSS/JS, so that one can better integrate tools like Sass/Less or TypeScript/CoffeeScript, but it is currently just on my private branch and very far away from a public release. The goal is to stick to the standard library paradigm and don’t introduce unnecessary abstraction / computation as far as possible. |
@rbugajewski @sardar01 In my opinion, the cache related headers can control the behavior of caching servers.
|
@an-tao Thanks for the info. The cache related headers are actually the problem here. In order to improve loading performance, you need a pretty aggressive cache. Many enterprise CDNs have these values very high by default and some even don’t let you change them under a certain threshold. It also takes time for the content to replicate around the world to become available in a distributed fashion across the whole CDN, which is more of a technical restriction of the CDNs itself, but still relevant to this discussion. In general this isn’t an issue, because assets don’t change very often, but when they change you want all clients to use new assets. Because you can’t control browser caches, but have pretty high values in the cache related headers, you have an issue. The only solution you have now is to rename the asset to a filename you are sure wasn’t previously used, and edit your CSP pages everywhere the asset is used which can be a very tedious and boring job depending on the project size. This way you can make sure that the client will get the new asset, as the filename is completely unknown to the browser’s cache. Use Case
To handle this use case I have the following ideas and already started to work on a couple of them:
Do you have some feedback? What do you think about adding this functionality to Drogon once I finish work on this, and clean it up? |
If my memory serves me correctly, the Rails asset pipeline consists of joining all of the static resource files in a directory tree. This joined file is then minimized for size and given a "fingerprint" name which is a cryptographic hash of the minified fie contents. This is meant for deployment in production environments only. Regarding referencing assets in a CSP file, we can note that these files will often have to include custom tags which have a special meaning for front-end frameworks such as for example, Vue. So using tags keeps with this "HTML" design philosophy. On the other hand if we use function calls to reference individual assets, we open up the ability to manipulate the asset at compile time with function arguments. It appears that the second alternative is better. The application that I am working on is a lawyer's trust accounting application. Drogon + Vue + Websockets. Previously it would have been done in Ruby/Rails or Python/Django. |
This is very useful functionality, I'm looking forward to this. |
Yes, that’s what most web frameworks I know do to generate JavaScript and CSS files. This shouldn’t be a big deal from the perspective of Drogon, as most of the functionality is part of the other tools in the pipeline (like TypeScript or Sass). We should just make sure to properly integrate these kind of tools into Drogon’s pipeline, where most of the functionality should reside in
I agree that a custom tag is in line with the developers’ expectations. I would go for a custom tag in this case. You could then always use
Yes, that’s in fact how some parts are already implemented, but I don’t see a way for plugins to extend the template syntax with additional tags, so this would probably have to be done outside of the plugin? |
@rbugajewski What do you mean when you said extending the template syntax with additional tags? could you show me a example of it? |
@an-tao I was thinking about special markup symbols like they are described in the view section of the official documentation, as it is currently the case with
What do you think? |
Great! I see what you mean. How about introducing a configuration object into csp files? e. g.:
and then we can change static resources without rebuilding anything. |
Another requirement may be related to this, can it also solve the multi-language support? |
I agree that a custom tag is in line with the developers’ expectations. I would go for a custom tag in this case. You could then always use <%c++ /* code */ %> in the CSP template to access the Asset API in case you need advanced behavior. I think that we would have the best of both worlds with this solution. Yes, I do believe that you are right. Regarding configuration files:
This is very cool. I presume, that these JSON files (their properties) can be written/rewritten at compile time and also at run-time. And classes of objects (for example, images) can be associated with a particular config file. Are you also thinking (alluding?) to the ability to define a new CSP markup symbol from a subject JSON file? Appears to be a very ambitious idea. |
MVC web frameworks such as Rails and Django typically have a static directory for storing static resources such as images, css and javascript files. In Drogon, it appears that these resources cannot be specified and statically linked into the executable. Evidently <%view > cannot be used in csp files in order to "include" these resources in a HTML page.
A link such as <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> for example, works perfectly in Drogon but it does not appear to be accessible when the path is local, such as for example: <script src="static/javascript/jquery.min.js">. Am I missing something or is this a missing feature? The second issue is that these types of static resources are typically cached upstream or served by a specialized server. How would Drogon enable such caching. Thank you.
The text was updated successfully, but these errors were encountered: