I'm working on a Java site (jQuery, Wicket, Maven, Spring, Hibernate) and we have just started using a CDN to serve static files on our production server. We use a placeholder for the CDN domain, and have added it to every static file that references a static file. The placeholder gets replaced by Maven through properties filters with Maven.
So, for every static file served by the CDN, we have something like this:
<img src="${placeholder}/images/dogs/rex.jpg"/>
For production, ${placeholder} is replaced with "http://cdn.com" and for development environments, it is replaced with blank.
...Is there a better way? It seems unusual to globally add a Maven-specific placeholder to the static files themselves. It will need to be added for every new image going forward, as well. In addition, changes to static files MUST go through a Maven build before those changes will show in a browser, and this slows down development in certain environments. This is probably avoidable, but still seems unnecessary in the first place.
When we used to do this kind of thing, we would have the cdn url be a property exposed by an application scoped spring bean, then you can inject this property in your applicationContext.xml and that's where you would replace it with the maven filter. Then we reference an EL expression with that property in the jsps.
Related
In my ASP.NET Core 5 application, I use ~/ to resolve to the root of the content directory.
However, I've now switched to hosting all the static files on a CDN (uploading anything in wwwroot at build time).
Is there a way to modify the ~ resolution so that it gives me a path like https://cdn.example.com/foo-asset instead of /foo-asset like it normally does?
I tried setting the IHostingEnvironment.WebRootPath property, however that can't handle URLs, and it looks like it also does something different than what I want (it tells the server where to read static files from, instead of telling it where ~/ should resolve to)
Another option is to use a method to do the resolution wherever I use these paths, like <a href=#ResolveCdn("~/foo-asset")> but I would rather not do this if at all possible.
We're currently setting up a Spartacus application running on CCv2 with three different enviroments (dev, stage, prod).
We are struggling to set the right OCC API Urls, within Spartacus, for the enviroment, I guess the way to go are enviroment variables, as this is Angular standard, but we couldn't find a way to match the enviroment vars to the corresponding system.
Is there something we're missing?
Thanks for your help!
The OCC baseUrl can actually be provided by CCv2 automatically. This is described in the docs.
It works like this:
Add a static meta tag in your index.html, with placeholder content
<meta name="occ-backend-base-url" content="OCC_BACKEND_BASE_URL_VALUE" />
The placeholder will get replaced automatically by CCv2
Remove the static configured baseUrl in the Spartacus configuration, as this will take precedence over the meta tag (we're about to change this)
This is however the only configuration that is environment specific, the ticket referenced by Grin is indeed a feature that we like to add.
We faced the same issue in our project.
It is was already reported as an issue on Spartacus Github page .
I am building a Mule domain using Maven which works fine, except the zip file it creates is named MyDomain-1.0.0.0.zip
Mule (community edition) will bring up this domain with a domain name of MyDomain-1.0.0.0 when deployed.
I want the name to be MyDomain. I cannot find a way of specifying the domain name which is used - it seems Mule always uses the zip file name.
The reason i want to do this is because the applications in the domain are coded to use MyDomain, and obviously fail if the domain isnt named as such.
When running in AnyPoint, the domain is named after the project name, and I dont want to have to change the project name in Anypoint to include the version number.
Is this possible please? the only way round it ive found is to rename the zip file to MyDomain.zip, which I dont want to do since I want releases to have unique zip filenames (but keep the same domain name)
You can use the finalName child tag of build i.e:
<build>
<finalName>myapp</finalName>
</build>
Use the domain including the version. It would allow you to have apps run in different versions of a domain without the requirement of a turn-key switch to a new domain version.
So, create a project called 'myDomain' (you probably have that) and set in the mule-project.xml of your domain that the domain is 'myDomain-1.0.0'. This would allow the versioning of both the domains and the api referencing them to be handled by maven versioning and not force any weird and ugly things like using finalName (which forfeits all SNAPSHOT and versioning capabilities).
Also, you are now free to develop a myDomain2 and let it propagate the 'myDomain-2.0.0' domain. The reference of every app to it's domain in the pom.xml will be just as it's suppose to be. An app will just request 'myDomain-1.0.0' from the .m2 maven repo and it will find it.
I'm writing my magento extension and came up with a question. The main extension files/directory structure is quite clear. We have dirs for extension configuration files, models, helpers, database resources, frontend and backend scripts and stylesheets etc.
But what if my extension uses some files that aren't classes or resources to be included to frontend or backend?
For instance: image files that will only be attached to emails and will never be retrieved by a browser directly.
Should/could I just create a directory /app/code/community/MyNamespace/MyExtensionName/images?
The same dir tree for better readability:
app
code
community
MyNamespace
MyExtensionName
images
Or is there any other correct/recommended way to achieve that?
There's never been clear guidance on how to do this from Magento Inc. itself, and Magento's module structure doesn't offer clear guidance. The approach I've always taken is
Pretend I'm on the Magento core team
Pretend my fellow team members are sociopaths who don't care if anything I've done breaks
If you're adding frontend files for public consumption (to js, skin, etc), I always create a folder that's a lowercase version of my full module name, and drop all files in there
/js/namespace_modulename/file.js
In the case of files that aren't going to be served publicly (i.e. you only need access to them via PHP), creating a folder in the root of your module (as you've done above) is appropriate. I'd suggest something like
app
code
community
MyNamespace
MyExtensionName
assets
images
You never know when there'll be something else you want to add, and having everything under one folder will help keep the module structure clean.
There's even sort of a precedent for this in Magento's core code. Take a look at the
app/code/core/Mage/Sales/doc
folder.
Create a folder into media directory and place your files/images into that folder
media
MyExtensionName
images
And access them like
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'/MyExtensionName/images/pic.jpg';
Is there any way to automatically minify static content and then serve it from a cache automatically? Similar to have mod_compress/mod_deflate work? Preferably something I could use in combination with compression (since compression has a more noticeable benefit).
My preference is something that works with lighttpd but I haven't been able to find anything, so any web server that can do it would be interesting.
You can try nginx's third party Strip module:
http://wiki.nginx.org/NginxHttpStripModule
Any module you use is just going to remove whitespace. You'll get a better result by using a minifier that understands whatever you're minifying. e.g. Google's Closure javascript compiler.
It's smart enough to know what a variable is and make it's name shorter. A whitespace remover can't do that.
I'd recommend minifying offline unless your site is very low traffic. But if you want to minify in your live environment I recommend using nginx's proxy cache. (Sorry but I don't have enough reputation to post more than one link)
Or you can look into memcached for an in-memory cache or Redis for the same thing but with disk backup.
I decided to do this through PHP (mostly because I didn't feel like writing a lighttpd module).
My script takes in a query string specifying the type of the files requested (js or css), and then the names of those files. For example, on my site the CSS is added like this:
<link rel="stylesheet" href="concat.php?type=css&style&blue" ... />
This minifies and concatenates style.css and blue.css
It uses JSMin-PHP and cssmin.
It also caches the files using XCache if it's available (since minifying is expensive). I actually plan to change the script so it doesn't minify if Xcache isn't available, but I have Xcache and I got bored.
Anyway, if anyone else wants it, it's here. If you use mine you'll need to change the isAllowed() function to list your files (it may be safe to make it just return true, but it was easy to just list the ones I want to allow).
I use Microsoft Ajax Minifier which comes with a C# library to minify js files. I use that on the server and serve up a maximum of two minified .js files per page (one "static" one that is the same across the whole site, and one "dynamic" one that is specific to just that page).
Yahoo's YUI compressor is also a simple Java .jar file that you could use as well.
The important thing, I think, is not to do it on a file-by-file basis. You really do need to combine the .js files to get the most benefit. For that reason, an "automatic" solution is not really going to work - because it will necessarily only work on a file-by-file basis.
If you use Nginx instead of lighttpd then you can take advantage of Nginx's embedded Perl support to leverage the Perl module JavaScript-Minifier to minify and cache JS server-side.
Here are the details on how to achieve this: wiki.nginx.org/NginxEmbeddedPerlMinifyJS