I've created a module foo that has an includes directory, which in turn contains a js directory, which has a file in it named edit.js.
I've tried the following in a view of the module:
<script src="/myApp/foo/includes/js/edit.js"></script>
But I get a 404.
What's the proper way to reference modules' static assets?
Just took a bit more searching:
<script src="#event.getModuleRoot()#/includes/js/edit.js"></script>
You can also use
<script src="#event.buildLink('')#includes/js/edit.js"></script>
Related
With thymeleaf and following code
<script th:src="#{/js/init.js}"></script>
I would like to make it like following in order to avoid browser caching for this file
<script th:src="#{/js/init.js?${minute}}"></script>
${minute} will be current time minute.
Try:
<script th:src="#{/js/init.js(minute=${minute})}"></script>
Reference: Standard URL Syntax
I solve the question by use the following, it's a bit longer than expected.
<script th:src="#{/js/init.js(minute=${#dates.format(#dates.createNow(), 'mm')})}"></script>
If you just want to provide versioned static files, you might try spring resource versioning. One possible solution using configuration only is described here https://stackoverflow.com/a/49040930.
I use asp.net core 1.1.0. Main site published on a domain for example: site.com and all static files like css and js placed on a subdomain name static.site.com.
When use ScriptTagHelper as following, i expected that according to usage of asp-append-version attribute, version number append to js src but this not occur.
<script asp-append-version="true" src="http://static.site.com/js/site.js"></script>
I expected Something like this after rendered page
<script src="http://static.site.com/js/site.js?v=aNhFqVVmQXye2UDIUacX63ZaYbHi3fiDjhBhTA2aCCo"></script>
But result is:
<script src="http://static.site.com/js/site.js"></script>
The ScriptTagHelper does not append versions on files that are referenced via an absolute URI path. Here's the code responsible.
Dear all I have the following folders angular_components
Now for loading this files inside this folder I wrote
//= require_tree ./angular-components
The way files are loaded are
<script src="/assets/angular-components/mapAutoComplete/autoCompleteAddressApp.js?body=1"></script>
<script src="/assets/angular-components/mapAutoComplete/directive/controllers/googleAddressSuggestion.js?body=1"></script>
<script src="/assets/angular-components/mapAutoComplete/directive/googleAddressSuggestion.js?body=1"></script>
<script src="/assets/angular-components/mapAutoComplete/services/locationDataService.js?body=1"></script>
<script src="/assets/angular-components/stripePayment/lib/angularPayment.js?body=1"></script>
<script src="/assets/angular-components/stripePayment/services/stripeService.js?body=1"></script>
<script src="/assets/angular-components/stripePayment/stripePaymentApp.js?body=1"></script>
In the mapAutoComplete directory the file in the root folder autoCompleteAddressApp.js loaded before the other file however in the stripe payment the stripePaymentApp.js which is in the root folder loaded at the end. Why this is happening? How can I make sure in both cases the root file loaded before the child directory file?
The reason for this is require_tree loads the files or folders alphabetically whether it is a file or folder. One a way of solving your problem is individually loading the file without using require_tree. Another way you can achieve your goal is by adding _ underscore before the file you want to load first. Because require_tree will load the file prefixed with underscore before the other files. So in your case your directory structure would like following
I am working on a rails project where I have multiple users. I have used the standard architecture to create multiple users. I am trying not to use the asset pipeline for now for rendering CSS and JS files.
By default, on my homepage, when i include a JS or CSS file, it automatically looks in the public folder in my rails project folder. for example:
html.erb file 'include tags':
<link rel="stylesheet" href="css/default.css">
<script language="javascript" type="text/javascript" src="js/default.js"></script>
These 2 lines of code now look for the 'public/css/defaults.css' and 'public/js/default.js' respectively.
However, when I SHOW a single user, now the url path changes to for example: www.mywebsite.com/user/13
As a result, now the same 2 include tags for CSS and JS now point to 'public/user/css/defaults.css' and 'public/user/js/defaults.js'. I am having to duplicate the JS and CSS files in a public/user directory for the CSS and JS to be included in the user-show pages.
Is there a way to route the include tags back to the 'public' folder instead of the 'public/user' folder?
Did you try including a '/' for root?
<link rel="stylesheet" href="/css/default.css">
<script language="javascript" type="text/javascript" src="/js/default.js"></script>
Um trying to load a javascript file as follows to my html.erb file
<script src="/public/javascripts/test.js" type="text/javascript" />
its available on the public folder and its in the root directory
root/public/javascript
but it giving me an error saying
"NetworkError: 404 Not Found - http://0.0.0.0:3000/public/javascripts/test.js"
what could possibly wrong ? is there a different way to include a javascipt file in rails ?
If the javascript file is in any of the asset folders (assets, vendor, bundle) for Rails 3.x) you can add the script to your html.erb file by adding the following:
<%= javascript_include_tag('test.js') %>
You don't use public. Public is the implied root of the server.
The server will look for a file in public, then try to route it through your router if it doesn't find a match.
You also may want to consider using the javascript_include_tag helper if you are using the asset pipeline.
Rails defaults to using the asset pipeline, so custom js files need to go into the app/assets/javascript directory. Than you wouldn't even need to load the file in your view.
but as to your question.
To serve the files from the public directory, you will need to enable a config setting
config.serve_static_assets = true
You'd commonly put this in one of you environment config files.
To server files from public directory do above setting and hit
config.serve_static_assets = true
<script src="/javascripts/test.js" type="text/javascript" />